GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.11] gh-103861: Fix Zip64 extensions not being properly applied in some cases (GH-103863) by gpshead · Pull Request #104534 · python/cpython

Conversation

@gpshead

@gpshead gpshead commented May 16, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fix Zip64 extensions not being properly applied in some cases:

Fixes an issue where adding a small file to a ZipFile object while forcing zip64 extensions causes an extra Zip64 record to be added to the zip, but doesn't update the min_version or file sizes in the primary central directory header.

Also fixed an edge case in checking if zip64 extensions are required:

This fixes an issue where if data requiring zip64 extensions was added to an unseekable stream without specifying force_zip64=True, zip64 extensions would not be used and a RuntimeError would not be raised when closing the file (even though the size would be known at that point). This would result in successfully writing corrupt zip files.

Deciding if zip64 extensions are required outside of the FileHeader function means that both FileHeader and _ZipWriteFile will always be in sync. Previously, the FileHeader function could enable zip64 extensions without propagating that decision to the _ZipWriteFile class, which would then not correctly write the data descriptor record or check for errors on close.

If anyone is actually using ZipInfo.FileHeader as a public API without explicitly passing True or False in for zip64, their own code may still be susceptible to that kind of bug unless they make a similar change to where the zip64 decision happens.

Fixes GH-103861


(cherry picked from commit 798bcaa)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pR0Ps @gpshead
[3.11] pythongh-103861: Fix Zip64 extensions not being properly appli…
f09ad48
…ed in some cases (pythonGH-103863)

Fix Zip64 extensions not being properly applied in some cases:

Fixes an issue where adding a small file to a `ZipFile`
object while forcing zip64 extensions causes an extra Zip64 record to be
added to the zip, but doesn't update the `min_version` or file sizes in
the primary central directory header.

Also fixed an edge case in checking if zip64 extensions are required:

This fixes an issue where if data requiring zip64 extensions was added
to an unseekable stream without specifying `force_zip64=True`, zip64
extensions would not be used and a RuntimeError would not be raised when
closing the file (even though the size would be known at that point).
This would result in successfully writing corrupt zip files.

Deciding if zip64 extensions are required outside of the `FileHeader`
function means that both `FileHeader` and `_ZipWriteFile` will always be
in sync. Previously, the `FileHeader` function could enable zip64
extensions without propagating that decision to the `_ZipWriteFile`
class, which would then not correctly write the data descriptor record
or check for errors on close.

If anyone is actually using `ZipInfo.FileHeader` as a public API without
explicitly passing True or False in for zip64, their own code may still be
susceptible to that kind of bug unless they make a similar change to
where the zip64 decision happens.

Fixes pythonGH-103861

---------

Co-authored-by: Gregory P. Smith <[email protected]>.
(cherry picked from commit 798bcaa)

Co-authored-by: Carey Metcalfe <[email protected]>
@gpshead gpshead added the type-bug An unexpected behavior, bug, or error label May 16, 2023
@gpshead gpshead self-assigned this May 16, 2023
@bedevere-bot bedevere-bot added the awaiting core review label May 16, 2023
@bedevere-bot bedevere-bot mentioned this pull request May 16, 2023
Writing a small file into a ZipFile while forcing zip64 extensions results in an incorrect zip file #103861
Closed
@gpshead gpshead changed the title [3.11] gh-103861: Fix Zip64 extensions not being properly applied in some cases [3.11] gh-103861: Fix Zip64 extensions not being properly applied in some cases (GH-103863) May 16, 2023
@bedevere-bot bedevere-bot mentioned this pull request May 16, 2023
gh-103861: Fix Zip64 extensions not being properly applied in some cases #103863
Merged
@bedevere-bot bedevere-bot added the sprint label May 16, 2023
@gpshead
gpshead merged commit 133bf09 into python:3.11 May 17, 2023
@bedevere-bot bedevere-bot removed the awaiting core review label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gpshead gpshead

Labels

sprint type-bug An unexpected behavior, bug, or error

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@gpshead @bedevere-bot @pR0Ps
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.