From 29034baf58156e2462b0680e9092c0a3cccb0798 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 18 Sep 2018 23:28:34 +0300 Subject: [PATCH] [2.7] bpo-34341: Fix appending to ZIP archives with the ZIP64 extension. (GH-8683). (GH-9400) (cherry picked from commit 9bdb7be482aef8f60daa1d36606568a132dcb616) --- Lib/test/test_zipfile.py | 14 ++++++++++++ Lib/zipfile.py | 22 +++++++++++++++++++ .../2018-08-06-11-01-18.bpo-34341.E0b9p2.rst | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-08-06-11-01-18.bpo-34341.E0b9p2.rst diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 9c63aebbbe0e..4e545f140a83 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -812,6 +812,20 @@ class TestZip64InSmallFiles(unittest.TestCase): self.assertEqual(content, "%d" % (i**3 % 57)) zipf2.close() + def test_append(self): + # Test that appending to the Zip64 archive doesn't change + # extra fields of existing entries. + with zipfile.ZipFile(TESTFN2, "w", allowZip64=True) as zipfp: + zipfp.writestr("strfile", self.data) + with zipfile.ZipFile(TESTFN2, "r", allowZip64=True) as zipfp: + zinfo = zipfp.getinfo("strfile") + extra = zinfo.extra + with zipfile.ZipFile(TESTFN2, "a", allowZip64=True) as zipfp: + zipfp.writestr("strfile2", self.data) + with zipfile.ZipFile(TESTFN2, "r", allowZip64=True) as zipfp: + zinfo = zipfp.getinfo("strfile") + self.assertEqual(zinfo.extra, extra) + def tearDown(self): zipfile.ZIP64_LIMIT = self._limit zipfile.ZIP_FILECOUNT_LIMIT = self._filecount_limit diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 3ab66cea69d8..0f890ac6f3ab 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -131,6 +131,27 @@ _CD64_NUMBER_ENTRIES_TOTAL = 7 _CD64_DIRECTORY_SIZE = 8 _CD64_OFFSET_START_CENTDIR = 9 +_EXTRA_FIELD_STRUCT = struct.Struct('