gh-118107: Fix zipimporter ZIP64 handling. (GH-118108)

Add missing import to code that handles too large files and offsets.
Use list, not tuple, for a mutable sequence.

Add tests to prevent similar mistakes.

---------

Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
This commit is contained in:
John Sirois 2024-05-07 02:23:27 -05:00 committed by GitHub
parent 698417f2f6
commit 49258efada
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 128 additions and 3 deletions

View file

@ -517,8 +517,9 @@ def _read_directory(archive):
num_extra_values = (len(extra_data) - 4) // 8
if num_extra_values > 3:
raise ZipImportError(f"can't read header extra: {archive!r}", path=archive)
values = struct.unpack_from(f"<{min(num_extra_values, 3)}Q",
extra_data, offset=4)
import struct
values = list(struct.unpack_from(f"<{min(num_extra_values, 3)}Q",
extra_data, offset=4))
# N.b. Here be dragons: the ordering of these is different than
# the header fields, and it's really easy to get it wrong since