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

Skip to content

Commit 4ba3b50

Browse files
silasserhiy-storchaka
authored andcommitted
bpo-34472: Add data descriptor signature to zipfile (GH-8871)
This makes streamed zips compatible with MacOS Archive Utility and other applications.
1 parent d0f49d2 commit 4ba3b50

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Lib/zipfile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class LargeZipFile(Exception):
159159
_CD64_DIRECTORY_SIZE = 8
160160
_CD64_OFFSET_START_CENTDIR = 9
161161

162+
_DD_SIGNATURE = 0x08074b50
163+
162164
_EXTRA_FIELD_STRUCT = struct.Struct('<HH')
163165

164166
def _strip_extra(extra, xids):
@@ -1118,8 +1120,8 @@ def close(self):
11181120
# Write updated header info
11191121
if self._zinfo.flag_bits & 0x08:
11201122
# Write CRC and file sizes after the file data
1121-
fmt = '<LQQ' if self._zip64 else '<LLL'
1122-
self._fileobj.write(struct.pack(fmt, self._zinfo.CRC,
1123+
fmt = '<LLQQ' if self._zip64 else '<LLLL'
1124+
self._fileobj.write(struct.pack(fmt, _DD_SIGNATURE, self._zinfo.CRC,
11231125
self._zinfo.compress_size, self._zinfo.file_size))
11241126
self._zipfile.start_dir = self._fileobj.tell()
11251127
else:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ Roger D. Serwy
14681468
Jerry Seutter
14691469
Pete Sevander
14701470
Denis Severson
1471+
Silas Sewell
14711472
Ian Seyer
14721473
Dmitry Shachnev
14731474
Anish Shah
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improved compatibility for streamed files in :mod:`zipfile`. Previously an
2+
optional signature was not being written and certain ZIP applications were
3+
not supported. Patch by Silas Sewell.

0 commit comments

Comments
 (0)