]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.11] gh-103861: Fix Zip64 extensions not being properly applied in some cases ...
authorGregory P. Smith <greg@krypto.org>
Wed, 17 May 2023 08:07:10 +0000 (01:07 -0700)
committerGitHub <noreply@github.com>
Wed, 17 May 2023 08:07:10 +0000 (01:07 -0700)
commit133bf0927e9cb07d4a5a3ca31791ce18da22707b
tree7778b368e0a58115bf987b60b8245b165dcbd42c
parent3ce7d57c8aef98f599bb55d67585a8150ce6d775
[3.11] gh-103861: Fix Zip64 extensions not being properly applied in some cases (GH-103863) (#104534)

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 798bcaa1eb01de7db9ff1881a3088603ad09b096)

Co-authored-by: Carey Metcalfe <carey@cmetcalfe.ca>
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS.d/next/Library/2023-04-25-19-58-13.gh-issue-103861.JeozgD.rst [new file with mode: 0644]