Index: Lib/zipfile.py =================================================================== --- Lib/zipfile.py (revision 66890) +++ Lib/zipfile.py (working copy) @@ -1175,8 +1175,9 @@ pos2 = self.fp.tell() # Write end-of-zip-archive record + dirCount = count centDirOffset = pos1 - if pos1 > ZIP64_LIMIT: + if pos1 > ZIP64_LIMIT or count >= ZIP_FILECOUNT_LIMIT: # Need to write the ZIP64 end-of-archive records zip64endrec = struct.pack( structEndArchive64, stringEndArchive64, @@ -1187,6 +1188,7 @@ structEndArchive64Locator, stringEndArchive64Locator, 0, pos2, 1) self.fp.write(zip64locrec) + dirCount = 0xFFFF centDirOffset = 0xFFFFFFFF # check for valid comment length @@ -1197,8 +1199,7 @@ self.comment = self.comment[:ZIP_MAX_COMMENT] endrec = struct.pack(structEndArchive, stringEndArchive, - 0, 0, count % ZIP_FILECOUNT_LIMIT, - count % ZIP_FILECOUNT_LIMIT, pos2 - pos1, + 0, 0, dirCount, dirCount, pos2 - pos1, centDirOffset, len(self.comment)) self.fp.write(endrec) self.fp.write(self.comment)