Revert "Issue #29094: Offsets in a ZIP file created with extern file … · python/cpython@ef4c6ba (original) (raw)

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

`

772

772

`# set the modified flag so central directory gets written

`

773

773

`# even if no files are added to the archive

`

774

774

`self._didModify = True

`

775

``

`-

self._start_disk = 0

`

776

775

`elif key == 'a':

`

777

776

`try:

`

778

777

`# See if file is a zip file

`

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

`

786

785

`# set the modified flag so central directory gets written

`

787

786

`# even if no files are added to the archive

`

788

787

`self._didModify = True

`

789

``

`-

self._start_disk = self.fp.tell()

`

790

788

`else:

`

791

789

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

`

792

790

`except:

`

`@@ -817,18 +815,17 @@ def _RealGetContents(self):

`

817

815

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

`

818

816

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

`

819

817

``

820

``

`-

self._start_disk: Position of the start of ZIP archive

`

821

``

`-

It is zero, unless ZIP was concatenated to another file

`

822

``

`-

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

`

``

818

`+

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

`

``

819

`+

concat = endrec[_ECD_LOCATION] - size_cd - offset_cd

`

823

820

`if endrec[_ECD_SIGNATURE] == stringEndArchive64:

`

824

821

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

`

825

``

`-

self._start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator)

`

``

822

`+

concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator)

`

826

823

``

827

824

`if self.debug > 2:

`

828

``

`-

inferred = self._start_disk + offset_cd

`

829

``

`-

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

`

``

825

`+

inferred = concat + offset_cd

`

``

826

`+

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

`

830

827

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

`

831

``

`-

self.start_dir = offset_cd + self._start_disk

`

``

828

`+

self.start_dir = offset_cd + concat

`

832

829

`fp.seek(self.start_dir, 0)

`

833

830

`data = fp.read(size_cd)

`

834

831

`fp = cStringIO.StringIO(data)

`

`@@ -858,7 +855,7 @@ def _RealGetContents(self):

`

858

855

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

`

859

856

``

860

857

`x._decodeExtra()

`

861

``

`-

x.header_offset = x.header_offset + self._start_disk

`

``

858

`+

x.header_offset = x.header_offset + concat

`

862

859

`x.filename = x._decodeFilename()

`

863

860

`self.filelist.append(x)

`

864

861

`self.NameToInfo[x.filename] = x

`

`@@ -1201,7 +1198,7 @@ def write(self, filename, arcname=None, compress_type=None):

`

1201

1198

`raise RuntimeError('Compressed size larger than uncompressed size')

`

1202

1199

`# Seek backwards and write file header (which will now include

`

1203

1200

`# correct CRC and file sizes)

`

1204

``

`-

position = self.fp.tell() # Preserve current position in file

`

``

1201

`+

position = self.fp.tell() # Preserve current position in file

`

1205

1202

`self.fp.seek(zinfo.header_offset, 0)

`

1206

1203

`self.fp.write(zinfo.FileHeader(zip64))

`

1207

1204

`self.fp.seek(position, 0)

`

`@@ -1287,10 +1284,11 @@ def close(self):

`

1287

1284

`file_size = zinfo.file_size

`

1288

1285

`compress_size = zinfo.compress_size

`

1289

1286

``

1290

``

`-

header_offset = zinfo.header_offset - self._start_disk

`

1291

``

`-

if header_offset > ZIP64_LIMIT:

`

1292

``

`-

extra.append(header_offset)

`

``

1287

`+

if zinfo.header_offset > ZIP64_LIMIT:

`

``

1288

`+

extra.append(zinfo.header_offset)

`

1293

1289

`header_offset = 0xffffffffL

`

``

1290

`+

else:

`

``

1291

`+

header_offset = zinfo.header_offset

`

1294

1292

``

1295

1293

`extra_data = zinfo.extra

`

1296

1294

`if extra:

`

`@@ -1334,7 +1332,7 @@ def close(self):

`

1334

1332

`# Write end-of-zip-archive record

`

1335

1333

`centDirCount = len(self.filelist)

`

1336

1334

`centDirSize = pos2 - pos1

`

1337

``

`-

centDirOffset = pos1 - self._start_disk

`

``

1335

`+

centDirOffset = pos1

`

1338

1336

`requires_zip64 = None

`

1339

1337

`if centDirCount > ZIP_FILECOUNT_LIMIT:

`

1340

1338

`requires_zip64 = "Files count"

`