summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2009-01-17 16:40:17 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2009-01-17 16:40:17 (GMT)
commitd25f87ae366f205a88ed925e826367c952eadfd1 (patch)
tree76dbd25cc35af0dac8eedd691de41f5107ed5f28
parentf320c2270104a2c4cf3285cb2adcbdff7e811004 (diff)
downloadcpython-d25f87ae366f205a88ed925e826367c952eadfd1.zip
cpython-d25f87ae366f205a88ed925e826367c952eadfd1.tar.gz
cpython-d25f87ae366f205a88ed925e826367c952eadfd1.tar.bz2
#3997: zipfiles generated with more than 65536 files could not be opened
with other applications. Reviewed by Martin, will backport to 2.6 and 3.0
-rw-r--r--Lib/zipfile.py20
-rw-r--r--Misc/NEWS3
2 files changed, 16 insertions, 7 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 66fe078..fedcb79 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -26,7 +26,7 @@ class LargeZipFile(Exception):
error = BadZipfile # The exception raised by this module
-ZIP64_LIMIT= (1 << 31) - 1
+ZIP64_LIMIT = (1 << 31) - 1
ZIP_FILECOUNT_LIMIT = 1 << 16
ZIP_MAX_COMMENT = (1 << 16) - 1
@@ -1187,19 +1187,26 @@ class ZipFile:
pos2 = self.fp.tell()
# Write end-of-zip-archive record
+ centDirCount = count
+ centDirSize = pos2 - pos1
centDirOffset = pos1
- if pos1 > ZIP64_LIMIT:
+ if (centDirCount >= ZIP_FILECOUNT_LIMIT or
+ centDirOffset > ZIP64_LIMIT or
+ centDirSize > ZIP64_LIMIT):
# Need to write the ZIP64 end-of-archive records
zip64endrec = struct.pack(
structEndArchive64, stringEndArchive64,
- 44, 45, 45, 0, 0, count, count, pos2 - pos1, pos1)
+ 44, 45, 45, 0, 0, centDirCount, centDirCount,
+ centDirSize, centDirOffset)
self.fp.write(zip64endrec)
zip64locrec = struct.pack(
structEndArchive64Locator,
stringEndArchive64Locator, 0, pos2, 1)
self.fp.write(zip64locrec)
- centDirOffset = 0xFFFFFFFF
+ centDirCount = min(centDirCount, 0xFFFF)
+ centDirSize = min(centDirSize, 0xFFFFFFFF)
+ centDirOffset = min(centDirOffset, 0xFFFFFFFF)
# check for valid comment length
if len(self.comment) >= ZIP_MAX_COMMENT:
@@ -1209,9 +1216,8 @@ class ZipFile:
self.comment = self.comment[:ZIP_MAX_COMMENT]
endrec = struct.pack(structEndArchive, stringEndArchive,
- 0, 0, count % ZIP_FILECOUNT_LIMIT,
- count % ZIP_FILECOUNT_LIMIT, pos2 - pos1,
- centDirOffset, len(self.comment))
+ 0, 0, centDirCount, centDirCount,
+ centDirSize, centDirOffset, len(self.comment))
self.fp.write(endrec)
self.fp.write(self.comment)
self.fp.flush()
diff --git a/Misc/NEWS b/Misc/NEWS
index 57a9bd9..2e9e47d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -137,6 +137,9 @@ Core and Builtins
Library
-------
+- Issue #3997: zipfiles generated with more than 65536 files could not be
+ opened with other applications.
+
- Issue #1162154: inspect.getmembers() now skips attributes that raise
AttributeError, e.g. a __slots__ attribute which has not been set.