Revert bpo-26293 for zipfile breakage. See also bpo-29094. (#1484) · python/cpython@3763ea8 (original) (raw)

`@@ -1109,7 +1109,6 @@ def init(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):

`

1109

1109

`# set the modified flag so central directory gets written

`

1110

1110

`# even if no files are added to the archive

`

1111

1111

`self._didModify = True

`

1112

``

`-

self._start_disk = 0

`

1113

1112

`try:

`

1114

1113

`self.start_dir = self.fp.tell()

`

1115

1114

`except (AttributeError, OSError):

`

`@@ -1135,7 +1134,7 @@ def init(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):

`

1135

1134

`# set the modified flag so central directory gets written

`

1136

1135

`# even if no files are added to the archive

`

1137

1136

`self._didModify = True

`

1138

``

`-

self.start_dir = self._start_disk = self.fp.tell()

`

``

1137

`+

self.start_dir = self.fp.tell()

`

1139

1138

`else:

`

1140

1139

`raise ValueError("Mode must be 'r', 'w', 'x', or 'a'")

`

1141

1140

`except:

`

`@@ -1179,18 +1178,17 @@ def _RealGetContents(self):

`

1179

1178

`offset_cd = endrec[_ECD_OFFSET] # offset of central directory

`

1180

1179

`self._comment = endrec[_ECD_COMMENT] # archive comment

`

1181

1180

``

1182

``

`-

self._start_disk: Position of the start of ZIP archive

`

1183

``

`-

It is zero, unless ZIP was concatenated to another file

`

1184

``

`-

self._start_disk = endrec[_ECD_LOCATION] - size_cd - offset_cd

`

``

1181

`+

"concat" is zero, unless zip was concatenated to another file

`

``

1182

`+

concat = endrec[_ECD_LOCATION] - size_cd - offset_cd

`

1185

1183

`if endrec[_ECD_SIGNATURE] == stringEndArchive64:

`

1186

1184

`# If Zip64 extension structures are present, account for them

`

1187

``

`-

self._start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator)

`

``

1185

`+

concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator)

`

1188

1186

``

1189

1187

`if self.debug > 2:

`

1190

``

`-

inferred = self._start_disk + offset_cd

`

1191

``

`-

print("given, inferred, offset", offset_cd, inferred, self._start_disk)

`

``

1188

`+

inferred = concat + offset_cd

`

``

1189

`+

print("given, inferred, offset", offset_cd, inferred, concat)

`

1192

1190

`# self.start_dir: Position of start of central directory

`

1193

``

`-

self.start_dir = offset_cd + self._start_disk

`

``

1191

`+

self.start_dir = offset_cd + concat

`

1194

1192

`fp.seek(self.start_dir, 0)

`

1195

1193

`data = fp.read(size_cd)

`

1196

1194

`fp = io.BytesIO(data)

`

`@@ -1230,7 +1228,7 @@ def _RealGetContents(self):

`

1230

1228

`t>>11, (t>>5)&0x3F, (t&0x1F) * 2 )

`

1231

1229

``

1232

1230

`x._decodeExtra()

`

1233

``

`-

x.header_offset = x.header_offset + self._start_disk

`

``

1231

`+

x.header_offset = x.header_offset + concat

`

1234

1232

`self.filelist.append(x)

`

1235

1233

`self.NameToInfo[x.filename] = x

`

1236

1234

``

`@@ -1701,10 +1699,11 @@ def _write_end_record(self):

`

1701

1699

`file_size = zinfo.file_size

`

1702

1700

`compress_size = zinfo.compress_size

`

1703

1701

``

1704

``

`-

header_offset = zinfo.header_offset - self._start_disk

`

1705

``

`-

if header_offset > ZIP64_LIMIT:

`

1706

``

`-

extra.append(header_offset)

`

``

1702

`+

if zinfo.header_offset > ZIP64_LIMIT:

`

``

1703

`+

extra.append(zinfo.header_offset)

`

1707

1704

`header_offset = 0xffffffff

`

``

1705

`+

else:

`

``

1706

`+

header_offset = zinfo.header_offset

`

1708

1707

``

1709

1708

`extra_data = zinfo.extra

`

1710

1709

`min_version = 0

`

`@@ -1751,7 +1750,7 @@ def _write_end_record(self):

`

1751

1750

`# Write end-of-zip-archive record

`

1752

1751

`centDirCount = len(self.filelist)

`

1753

1752

`centDirSize = pos2 - self.start_dir

`

1754

``

`-

centDirOffset = self.start_dir - self._start_disk

`

``

1753

`+

centDirOffset = self.start_dir

`

1755

1754

`requires_zip64 = None

`

1756

1755

`if centDirCount > ZIP_FILECOUNT_LIMIT:

`

1757

1756

`requires_zip64 = "Files count"

`