Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-72680: Fix false positives when using zipfile.is_zipfile()#134250

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 4 commits intopython:mainfromthatch:is_zipfile_verify
May 21, 2025

Conversation

thatch
Copy link
Contributor

@thatchthatch commentedMay 19, 2025
edited by bedevere-appbot
Loading

Rebased#5053 and fixed the impl to pass tests. Original PR and description below by@jjolly

Fix zipfile validation issue by ... providing more validation!

Originally, zipfile.is_zipfile() only checked the End Central Directory
signature. If the signature could be found in the last 64k of the file,
success! This produced false positives on any file with 'PK\x05\x06' in the
last 64k of the file - including PDFs and PNGs.

This is now corrected by actually validating the Central Directory location
and size based on the information provided by the End Central Directory
along with verifying the Central Directory signature of the first entry.

This should be sufficient for the vast number of zipfiles, but more could be
done to absolutely validate the zipfile content - such as validating all
local file headers and Central Directory entries.

jjollyand others added2 commitsMay 19, 2025 10:27
The zipfile.is_zipfile function would only search for the EndOfZipfilesection header. This failed to correctly identify non-zipfiles thatcontained this header. Now the zipfile.is_zipfile function verifiesthe first central directory entry.Changes:* Extended zipfile.is_zipfile to verify zipfile catalog* Added tests to validate failure of binary non-zipfiles
@gpsheadgpshead requested a review fromjaracoMay 19, 2025 18:38
@gpsheadgpshead self-assigned thisMay 19, 2025
@gpsheadgpshead added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelMay 19, 2025
@github-project-automationgithub-project-automationbot moved this fromTodo toIn Progress inSprint 2024May 19, 2025
@gpsheadgpshead added the needs backport to 3.14bugs and security fixes labelMay 19, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@gpshead for commit4bfec3e 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F134250%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelMay 19, 2025
Comment on lines 1 to 13
Improve Zip file validation in :func:`zipfile.is_zipfile`.

Before this change :func:`zipfile.is_zipfile` only checked the End Central Directory
signature. If the signature could be found in the last 64k of the file,
success! This produced false positives on any file with ``'PK\x05\x06'`` in the
last 64k of the file - including PDFs and PNGs.

This is now corrected by actually validating the Central Directory location
and size based on the information provided by the End of Central Directory
along with verifying the Central Directory signature of the first entry.

This should be sufficient for the vast number of Zip files with fewer
false positives.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very beefy NEWS, could it be condensed. We generally keep them quite brief, details go in issues or docs.

Copy link
Member

Choose a reason for hiding this comment

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

I suggest to move most of the NEWS entry into the commit message, and keep the NEWS entry short.

@gpsheadgpshead merged commit1298511 intopython:mainMay 21, 2025
39 checks passed
@miss-islington-app
Copy link

Thanks@thatch for the PR, and@gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 21, 2025
…ythonGH-134250)bpo-28494: Improve zipfile.is_zipfile reliabilityThe zipfile.is_zipfile function would only search for the EndOfZipfilesection header. This failed to correctly identify non-zipfiles thatcontained this header. Now the zipfile.is_zipfile function verifiesthe first central directory entry.Changes:* Extended zipfile.is_zipfile to verify zipfile catalog* Added tests to validate failure of binary non-zipfiles* Reuse 'concat' handling for is_zipfile(cherry picked from commit1298511)Co-authored-by: Tim Hatch <timhatch@netflix.com>Co-authored-by: John Jolly <john.jolly@gmail.com>
@bedevere-app
Copy link

GH-134401 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMay 21, 2025
gpshead pushed a commit that referenced this pull requestMay 21, 2025
…H-134250) (#134401)gh-72680: Fix false positives when using zipfile.is_zipfile() (GH-134250)bpo-28494: Improve zipfile.is_zipfile reliabilityThe zipfile.is_zipfile function would only search for the EndOfZipfilesection header. This failed to correctly identify non-zipfiles thatcontained this header. Now the zipfile.is_zipfile function verifiesthe first central directory entry.Changes:* Extended zipfile.is_zipfile to verify zipfile catalog* Added tests to validate failure of binary non-zipfiles* Reuse 'concat' handling for is_zipfile(cherry picked from commit1298511)Co-authored-by: Tim Hatch <timhatch@netflix.com>Co-authored-by: John Jolly <john.jolly@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner left review comments

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@gpsheadgpsheadgpshead approved these changes

@jaracojaracoAwaiting requested review from jaraco

Assignees

@gpsheadgpshead

Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@thatch@bedevere-bot@gpshead@vstinner@StanFromIreland@jjolly

[8]ページ先頭

©2009-2025 Movatter.jp