Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c3f8a4

Browse files
committed
Merged revisions 68661 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r68661 | amaury.forgeotdarc | 2009-01-17 17:40:17 +0100 (Sat, 17 Jan 2009) | 5 lines #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 ........
1 parent 0156dab commit 0c3f8a4

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

Lib/zipfile.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LargeZipFile(Exception):
2828

2929
error = BadZipfile # The exception raised by this module
3030

31-
ZIP64_LIMIT= (1 << 31) - 1
31+
ZIP64_LIMIT = (1 << 31) - 1
3232
ZIP_FILECOUNT_LIMIT = 1 << 16
3333
ZIP_MAX_COMMENT = (1 << 16) - 1
3434

@@ -1198,19 +1198,26 @@ def close(self):
11981198

11991199
pos2 = self.fp.tell()
12001200
# Write end-of-zip-archive record
1201+
centDirCount = count
1202+
centDirSize = pos2 - pos1
12011203
centDirOffset = pos1
1202-
if pos1 > ZIP64_LIMIT:
1204+
if (centDirCount >= ZIP_FILECOUNT_LIMIT or
1205+
centDirOffset > ZIP64_LIMIT or
1206+
centDirSize > ZIP64_LIMIT):
12031207
# Need to write the ZIP64 end-of-archive records
12041208
zip64endrec = struct.pack(
12051209
structEndArchive64, stringEndArchive64,
1206-
44, 45, 45, 0, 0, count, count, pos2 - pos1, pos1)
1210+
44, 45, 45, 0, 0, centDirCount, centDirCount,
1211+
centDirSize, centDirOffset)
12071212
self.fp.write(zip64endrec)
12081213

12091214
zip64locrec = struct.pack(
12101215
structEndArchive64Locator,
12111216
stringEndArchive64Locator, 0, pos2, 1)
12121217
self.fp.write(zip64locrec)
1213-
centDirOffset = 0xFFFFFFFF
1218+
centDirCount = min(centDirCount, 0xFFFF)
1219+
centDirSize = min(centDirSize, 0xFFFFFFFF)
1220+
centDirOffset = min(centDirOffset, 0xFFFFFFFF)
12141221

12151222
# check for valid comment length
12161223
if len(self.comment) >= ZIP_MAX_COMMENT:
@@ -1220,9 +1227,8 @@ def close(self):
12201227
self.comment = self.comment[:ZIP_MAX_COMMENT]
12211228

12221229
endrec = struct.pack(structEndArchive, stringEndArchive,
1223-
0, 0, count % ZIP_FILECOUNT_LIMIT,
1224-
count % ZIP_FILECOUNT_LIMIT, pos2 - pos1,
1225-
centDirOffset, len(self.comment))
1230+
0, 0, centDirCount, centDirCount,
1231+
centDirSize, centDirOffset, len(self.comment))
12261232
self.fp.write(endrec)
12271233
self.fp.write(self.comment)
12281234
self.fp.flush()

0 commit comments

Comments
 (0)