Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-126606: don't write incomplete pyc files #126627

Merged

Conversation

cfbolz
Copy link
Contributor

@cfbolz cfbolz commented Nov 9, 2024

fix corner case in importlib: so far, the code does not check the return value of _io.FileIO.write to see whether a pyc code was fully written to disk. If a ulimit is in place (or the disk is full or something), this could lead to truncated pyc files. After the fix, the written size is checked and the half-written file is removed.

@picnixz picnixz added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Nov 9, 2024
…e-126066.9zs4m4.rst

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

Some stylistic comments on the test and a question of what the best exception is.

Lib/importlib/_bootstrap_external.py Show resolved Hide resolved
Lib/importlib/_bootstrap_external.py Outdated Show resolved Hide resolved
Lib/test/test_importlib/test_util.py Outdated Show resolved Hide resolved
Lib/test/test_importlib/test_util.py Outdated Show resolved Hide resolved
Lib/test/test_importlib/test_util.py Outdated Show resolved Hide resolved
Lib/test/test_importlib/test_util.py Outdated Show resolved Hide resolved
Lib/test/test_importlib/test_util.py Outdated Show resolved Hide resolved
Lib/test/test_importlib/test_util.py Outdated Show resolved Hide resolved
@bedevere-app
Copy link

bedevere-app bot commented Nov 12, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

- use swap_attr instead of mock
- nicer comments
- remove magic constant
@cfbolz
Copy link
Contributor Author

cfbolz commented Nov 13, 2024

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Nov 13, 2024

Thanks for making the requested changes!

@brettcannon: please review the changes made to this pull request.

Lib/importlib/_bootstrap_external.py Outdated Show resolved Hide resolved
@brettcannon
Copy link
Member

Everything LGTM at this point (I just went ahead and tweaked a comment)! Once CI passes I will merge and hope the backports all succeed. 🤞

@brettcannon brettcannon enabled auto-merge (squash) November 13, 2024 21:07
@brettcannon brettcannon merged commit c695e37 into python:main Nov 13, 2024
36 checks passed
@miss-islington-app
Copy link

Thanks @cfbolz for the PR, and @brettcannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 13, 2024
(cherry picked from commit c695e37)

Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Brett Cannon <brett@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Nov 13, 2024

GH-126809 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Nov 13, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 13, 2024
(cherry picked from commit c695e37)

Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Brett Cannon <brett@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Nov 13, 2024

GH-126810 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Nov 13, 2024
brettcannon added a commit that referenced this pull request Nov 13, 2024
…6809)

GH-126606: don't write incomplete pyc files (GH-126627)
(cherry picked from commit c695e37)

Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Brett Cannon <brett@python.org>
brettcannon added a commit that referenced this pull request Nov 13, 2024
…6810)

GH-126606: don't write incomplete pyc files (GH-126627)
(cherry picked from commit c695e37)

Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Brett Cannon <brett@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants