From 3697da39e469c0b1538770a799bfcd780cf041a6 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sun, 28 Jun 2026 20:53:43 +0800 Subject: [PATCH 1/4] gh-152486: Fix duplicated zip64 extra in local file entry --- Lib/test/test_zipfile/test_core.py | 28 ++++++++++++++++++++++++++++ Lib/zipfile/__init__.py | 9 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index 4f20209927e7b3..abc47ea625c83b 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -1189,6 +1189,34 @@ def test_generated_valid_zip64_extra(self): self.assertEqual(zinfo.header_offset, expected_header_offset) self.assertEqual(zf.read(zinfo), expected_content) + def test_generated_valid_zip64_extra_in_local_entry(self): + """Should not write duplicated zip64 fields to the local file entry.""" + fh = io.BytesIO() + with zipfile.ZipFile(fh, 'w') as zh: + zinfo = zipfile.ZipInfo('strfile') + zinfo.extra = ( + # zip64 (should be stripped) + b'\x01\x00\x10\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00' + + # invalid tail + b'zzz' + ) + zh.writestr(zinfo, self.data) + + fh.seek(0) + fh.seek(zinfo.header_offset) + entry = fh.read(zh.start_dir - zinfo.header_offset - zinfo.compress_size) + header = struct.unpack_from(zipfile.structFileHeader, entry) + extra_bytes = entry[-header[zipfile._FH_EXTRA_FIELD_LENGTH]:] + self.assertEqual(extra_bytes, ( + b'\x01\x00\x10\x00' + b'!e\x00\x00\x00\x00\x00\x00' + b'!e\x00\x00\x00\x00\x00\x00' + b'zzz' + )) + def test_force_zip64(self): """Test that forcing zip64 extensions correctly notes this in the zip file""" diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 418933a2e8d9e8..6a3d49fd9a9d33 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -550,8 +550,13 @@ def FileHeader(self, zip64=None): zip64 = file_size > ZIP64_LIMIT or compress_size > ZIP64_LIMIT if zip64: fmt = ' Date: Mon, 29 Jun 2026 03:43:48 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst new file mode 100644 index 00000000000000..e223a5e2132e46 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst @@ -0,0 +1 @@ +Fix an issue where duplicated Zip64 extra fields were written if :attr:ZipInfo.extra already contained a Zip64 field. From b106f4f507b4eda2656ceacc85552c07a513f16c Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Mon, 29 Jun 2026 11:57:44 +0800 Subject: [PATCH 3/4] Fix syntax --- .../2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst index e223a5e2132e46..078549f36efe44 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst @@ -1 +1 @@ -Fix an issue where duplicated Zip64 extra fields were written if :attr:ZipInfo.extra already contained a Zip64 field. +Fix an issue where duplicated Zip64 extra fields were written if :attr:``ZipInfo.extra `` already contained a Zip64 field. From 6f9596b722cc08320790dc9c5f1054c60dfb5b1d Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Mon, 29 Jun 2026 12:01:05 +0800 Subject: [PATCH 4/4] Fix syntax --- .../2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst index 078549f36efe44..62ce56a7e641eb 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-29-03-43-41.gh-issue-152486.kASYh8.rst @@ -1 +1 @@ -Fix an issue where duplicated Zip64 extra fields were written if :attr:``ZipInfo.extra `` already contained a Zip64 field. +Fix an issue where duplicated Zip64 extra fields were written if :attr:`ZipInfo.extra ` already contained a Zip64 field.