Skip to content

Commit

Permalink
Properly read zip64 archives with non-empty zip64 extensible data sec…
Browse files Browse the repository at this point in the history
…tor in Zip64 end of central directory record

Fixes python#126834
  • Loading branch information
VladRassokhin committed Nov 14, 2024
1 parent 1e3497e commit b0f37b3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Lib/zipfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b0f37b3

Please sign in to comment.