Skip to content

Conversation

@AZero13
Copy link
Contributor

@AZero13 AZero13 commented Dec 20, 2025

We can literally just use open(path, 'xb+') for _create_carefully

@AZero13 AZero13 requested a review from a team as a code owner December 20, 2025 06:49
@AZero13 AZero13 changed the title gh-143010: Prevent a TOCTOU issue by reusing the fd gh-143010: Prevent a TOCTOU issue by only calling open once Dec 20, 2025
… TOCTOU issue by only calling open once

We can literally just use open(path, 'xb+') for _create_carefully.
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please start with a failing test that can show us what's wrong?

@AZero13
Copy link
Contributor Author

AZero13 commented Dec 20, 2025

Can you please start with a failing test that can show us what's wrong?

This is going to be very difficult given the fact it has to be precisely timed to the nanosecond as it is between opening of the file descriptor to the opening of the path again.

@AZero13
Copy link
Contributor Author

AZero13 commented Dec 21, 2025

By the way, this code is older than the "x" was added in 2012, which is why this wasn't used in the first place.

@bitdancer
Copy link
Member

I think that you can create a test by mocking open with a side_effect that munges things before making the real open call. Is that worth doing?

@bedevere-app
Copy link

bedevere-app bot commented Dec 21, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Co-authored-by: sobolevn <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants