Skip to content

gh-161945: reject zipfile compression mismatches - #161948

Merged
carljm merged 1 commit into
python:mainfrom
woodruffw-forks:ww/fix-161945
Nov 23, 2026
Merged

carljm merged 1 commit into
python:mainfrom
woodruffw-forks:ww/fix-161945

Conversation

@woodruffw

@woodruffw woodruffw commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

ZipFile.open now rejects a ZIP archive member whose compression fields (across the local file entry and central directory entry) disagree.

Signed-off-by: William Woodruff [email protected]

@woodruffw

Copy link
Copy Markdown
Contributor Author

NB I'd suggest backporting this to all non-EOL versions. It should be low risk as real, non-malicous ZIP encoders never mismatch the compression fields like this.

A ZIP archive has two distinct compression fields for
each member (central directory and local file).

The `zipfile` module now rejects an archive where a member's
compression fields do not match.

Signed-off-by: William Woodruff <[email protected]>

@carljm carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! PR description should be clarified to use wording more like the NEWS entry: the archive is not rejected, opening the individual member is rejected.

Should this same fix be extended to zipimport._get_data()? It seems like even after this PR, it still trusts the central directory's compression field.

@woodruffw

Copy link
Copy Markdown
Contributor Author

Thanks @carljm! I'll update the PR desc in a sec.

Should this same fix be extended to zipimport._get_data()? It seems like even after this PR, it still trusts the central directory's compression field.

Past security triage of zipfile has been split from zipimport under the theory/assumption that zipimport immediately executes code by design anyways, so there's limited value in hardening it. So I'd personally keep it split here.

@carljm
carljm merged commit a46c65c into python:main Nov 23, 2026
61 checks passed
@carljm carljm added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 23, 2026
@miss-islington-app

Copy link
Copy Markdown

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

@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

bedevere-app Bot commented Nov 23, 2026

Copy link
Copy Markdown

GH-162489 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 23, 2026
@bedevere-app

bedevere-app Bot commented Nov 23, 2026

Copy link
Copy Markdown

GH-162490 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 23, 2026
carljm pushed a commit that referenced this pull request Nov 23, 2026
…162489)

gh-161945: reject zipfile compression mismatches (GH-161948)

`ZipFile.open` now rejects a ZIP archive member whose compression fields (across the local file entry and central directory entry) disagree.
(cherry picked from commit a46c65c)

Signed-off-by: William Woodruff <[email protected]>
Co-authored-by: William Woodruff <[email protected]>
carljm pushed a commit that referenced this pull request Nov 23, 2026
…162490)

gh-161945: reject zipfile compression mismatches (GH-161948)

`ZipFile.open` now rejects a ZIP archive member whose compression fields (across the local file entry and central directory entry) disagree.
(cherry picked from commit a46c65c)

Signed-off-by: William Woodruff <[email protected]>
Co-authored-by: William Woodruff <[email protected]>
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.

2 participants