diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index fdf2cd26f8c7c64..03e6582ca17dc33 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -4156,6 +4156,23 @@ def test_read_zipfile_error(self): with self.assertRaises(zipfile.BadZipfile): zipfile.ZipFile(TESTFN, "r").close() + def test_read_zipfile_duplicate_unicode_path_extra_field(self): + filename = "이름.txt" + filename_crc = struct.pack('= 4: tp, ln = unpack(' len(extra): @@ -611,6 +612,12 @@ def _decodeExtra(self, filename_crc): raise BadZipFile(f"Corrupt zip64 extra field. " f"{field} not found.") from None elif tp == 0x7075: + # Parsers disagree on which one wins, so a member carrying more + # than one is ambiguous rather than merely redundant. + if seen_unicode_path: + raise BadZipFile( + "Duplicate unicode path extra field (0x7075)") + seen_unicode_path = True data = extra[4:ln+4] # Unicode Path Extra Field try: diff --git a/Misc/NEWS.d/next/Library/2026-08-30-11-58-04.gh-issue-154894.XFOjGQ.rst b/Misc/NEWS.d/next/Library/2026-08-30-11-58-04.gh-issue-154894.XFOjGQ.rst new file mode 100644 index 000000000000000..6317aec87c45fe8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-30-11-58-04.gh-issue-154894.XFOjGQ.rst @@ -0,0 +1,4 @@ +:mod:`zipfile` now rejects an archive member that carries more than one +Unicode Path extra field (``0x7075``) instead of silently using the last one. +ZIP parsers disagree on which of the duplicates wins, so such a member is +ambiguous rather than merely redundant.