From b0f37b36324899ac7e001e2f881ddf73f00efb7e Mon Sep 17 00:00:00 2001 From: Vladislav Rassokhin Date: Thu, 14 Nov 2024 21:50:25 +0100 Subject: [PATCH 1/2] Properly read zip64 archives with non-empty zip64 extensible data sector in Zip64 end of central directory record Fixes #126834 --- Lib/zipfile/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 08c83cfb760250..d220173c1c5c22 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -270,8 +270,7 @@ def _EndRecData64(fpin, offset, endrec): if diskno != 0 or disks > 1: raise BadZipFile("zipfiles that span multiple disks are not supported") - # Assume no 'zip64 extensible data' - fpin.seek(offset - sizeEndCentDir64Locator - sizeEndCentDir64, 2) + fpin.seek(reloff, 0) data = fpin.read(sizeEndCentDir64) if len(data) != sizeEndCentDir64: return endrec @@ -281,6 +280,8 @@ def _EndRecData64(fpin, offset, endrec): if sig != stringEndArchive64: return endrec + size_zip64_tail_records = sz + 12 + sizeEndCentDir64Locator + # Update the original endrec using data from the ZIP64 record endrec[_ECD_SIGNATURE] = sig endrec[_ECD_DISK_NUMBER] = disk_num @@ -289,6 +290,8 @@ def _EndRecData64(fpin, offset, endrec): endrec[_ECD_ENTRIES_TOTAL] = dircount2 endrec[_ECD_SIZE] = dirsize endrec[_ECD_OFFSET] = diroffset + # Adjust location for Zip64 extension structures + endrec[_ECD_LOCATION] -= size_zip64_tail_records return endrec @@ -1453,9 +1456,6 @@ def _RealGetContents(self): # "concat" is zero, unless zip was concatenated to another file concat = endrec[_ECD_LOCATION] - size_cd - offset_cd - if endrec[_ECD_SIGNATURE] == stringEndArchive64: - # If Zip64 extension structures are present, account for them - concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator) if self.debug > 2: inferred = concat + offset_cd From 4f57dc5dbe5ab0141ae0148f52a9b47c5b98f4d8 Mon Sep 17 00:00:00 2001 From: Vladislav Rassokhin Date: Sat, 16 Nov 2024 10:57:19 +0100 Subject: [PATCH 2/2] fixup! Properly read zip64 archives with non-empty zip64 extensible data sector in Zip64 end of central directory record --- Lib/zipfile/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index d220173c1c5c22..3bbd243bf4e00e 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -270,7 +270,7 @@ def _EndRecData64(fpin, offset, endrec): if diskno != 0 or disks > 1: raise BadZipFile("zipfiles that span multiple disks are not supported") - fpin.seek(reloff, 0) + fpin.seek(reloff, os.SEEK_SET) data = fpin.read(sizeEndCentDir64) if len(data) != sizeEndCentDir64: return endrec