From: Serhiy Storchaka Date: Tue, 18 Sep 2018 20:28:34 +0000 (+0300) Subject: [2.7] bpo-34341: Fix appending to ZIP archives with the ZIP64 extension. (GH-8683... X-Git-Tag: v2.7.16rc1~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29034baf58156e2462b0680e9092c0a3cccb0798;p=thirdparty%2FPython%2Fcpython.git [2.7] bpo-34341: Fix appending to ZIP archives with the ZIP64 extension. (GH-8683). (GH-9400) (cherry picked from commit 9bdb7be482aef8f60daa1d36606568a132dcb616) --- 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('