Skip to content

Commit 70dc6a7

Browse files
[3.6] Revert bpo-26293 for zipfile breakage. See also bpo-29094. (GH-1484). (#1485)
(cherry picked from commit 3763ea8)
1 parent 0fe870f commit 70dc6a7

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

Lib/zipfile.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
11101110
# set the modified flag so central directory gets written
11111111
# even if no files are added to the archive
11121112
self._didModify = True
1113-
self._start_disk = 0
11141113
try:
11151114
self.start_dir = self.fp.tell()
11161115
except (AttributeError, OSError):
@@ -1136,7 +1135,7 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
11361135
# set the modified flag so central directory gets written
11371136
# even if no files are added to the archive
11381137
self._didModify = True
1139-
self.start_dir = self._start_disk = self.fp.tell()
1138+
self.start_dir = self.fp.tell()
11401139
else:
11411140
raise ValueError("Mode must be 'r', 'w', 'x', or 'a'")
11421141
except:
@@ -1180,18 +1179,17 @@ def _RealGetContents(self):
11801179
offset_cd = endrec[_ECD_OFFSET] # offset of central directory
11811180
self._comment = endrec[_ECD_COMMENT] # archive comment
11821181

1183-
# self._start_disk: Position of the start of ZIP archive
1184-
# It is zero, unless ZIP was concatenated to another file
1185-
self._start_disk = endrec[_ECD_LOCATION] - size_cd - offset_cd
1182+
# "concat" is zero, unless zip was concatenated to another file
1183+
concat = endrec[_ECD_LOCATION] - size_cd - offset_cd
11861184
if endrec[_ECD_SIGNATURE] == stringEndArchive64:
11871185
# If Zip64 extension structures are present, account for them
1188-
self._start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator)
1186+
concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator)
11891187

11901188
if self.debug > 2:
1191-
inferred = self._start_disk + offset_cd
1192-
print("given, inferred, offset", offset_cd, inferred, self._start_disk)
1189+
inferred = concat + offset_cd
1190+
print("given, inferred, offset", offset_cd, inferred, concat)
11931191
# self.start_dir: Position of start of central directory
1194-
self.start_dir = offset_cd + self._start_disk
1192+
self.start_dir = offset_cd + concat
11951193
fp.seek(self.start_dir, 0)
11961194
data = fp.read(size_cd)
11971195
fp = io.BytesIO(data)
@@ -1231,7 +1229,7 @@ def _RealGetContents(self):
12311229
t>>11, (t>>5)&0x3F, (t&0x1F) * 2 )
12321230

12331231
x._decodeExtra()
1234-
x.header_offset = x.header_offset + self._start_disk
1232+
x.header_offset = x.header_offset + concat
12351233
self.filelist.append(x)
12361234
self.NameToInfo[x.filename] = x
12371235

@@ -1702,10 +1700,11 @@ def _write_end_record(self):
17021700
file_size = zinfo.file_size
17031701
compress_size = zinfo.compress_size
17041702

1705-
header_offset = zinfo.header_offset - self._start_disk
1706-
if header_offset > ZIP64_LIMIT:
1707-
extra.append(header_offset)
1703+
if zinfo.header_offset > ZIP64_LIMIT:
1704+
extra.append(zinfo.header_offset)
17081705
header_offset = 0xffffffff
1706+
else:
1707+
header_offset = zinfo.header_offset
17091708

17101709
extra_data = zinfo.extra
17111710
min_version = 0
@@ -1752,7 +1751,7 @@ def _write_end_record(self):
17521751
# Write end-of-zip-archive record
17531752
centDirCount = len(self.filelist)
17541753
centDirSize = pos2 - self.start_dir
1755-
centDirOffset = self.start_dir - self._start_disk
1754+
centDirOffset = self.start_dir
17561755
requires_zip64 = None
17571756
if centDirCount > ZIP_FILECOUNT_LIMIT:
17581757
requires_zip64 = "Files count"

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Revert bpo-26293 for zipfile breakage. See also bpo-29094.
40+
3941
- bpo-30243: Removed the __init__ methods of _json's scanner and encoder.
4042
Misusing them could cause memory leaks or crashes. Now scanner and encoder
4143
objects are completely initialized in the __new__ methods.

0 commit comments

Comments
 (0)