8000 bpo-34472: Add data descriptor signature to zipfile (GH-8871) (GH-9398) · python/cpython@ed21919 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed21919

Browse files
miss-islingtonsilas
authored andcommitted
bpo-34472: Add data descriptor signature to zipfile (GH-8871) (GH-9398)
This makes streamed zips compatible with MacOS Archive Utility and other applications. (cherry picked from commit 4ba3b50) Co-authored-by: Silas Sewell <silas@sewell.org>
1 parent 09f2eec commit ed21919

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
@@ -164,6 +164,8 @@ class LargeZipFile(Exception):
164164
_CD64_DIRECTORY_SIZE = 8
165165
_CD64_OFFSET_START_CENTDIR = 9
166166

167+
_DD_SIGNATURE = 0x08074b50
168+
167169
_EXTRA_FIELD_STRUCT = struct.Struct('<HH')
168170

169171
def _strip_extra(extra, xids):
@@ -1031,8 +1033,8 @@ def close(self):
10311033
# Write updated header info
10321034
if self._zinfo.flag_bits & 0x08:
10331035
# Write CRC and file sizes after the file data
1034-
fmt = '<LQQ' if self._zip64 else '<LLL'
1035-
self._fileobj.write(struct.pack(fmt, self._zinfo.CRC,
1036+
fmt = '<LLQQ' if self._zip64 else '<LLLL'
1037+
self._fileobj.write(struct.pack(fmt, _DD_SIGNATURE, self._zinfo.CRC,
10361038
self._zinfo.compress_size, self._zinfo.file_size))
10371039
self._zipfile.start_dir = self._fileobj.tell()
10381040
else:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ Roger D. Serwy
14191419
Jerry Seutter
14201420
Pete Sevander
14211421
Denis Severson
1422+
Silas Sewell
14221423
Ian Seyer
14231424
Dmitry Shachnev
14241425
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)
0