Commit 6ec29811 authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

[2.7] bpo-34472: Add data descriptor signature to zipfile (GH-8871) (ПР-9407)

This makes streamed zips compatible with MacOS Archive Utility and
other applications.
(cherry picked from commit 4ba3b50b)
Co-authored-by: default avatarSilas Sewell <silas@sewell.org>
parent fef3a92b
...@@ -131,6 +131,8 @@ _CD64_NUMBER_ENTRIES_TOTAL = 7 ...@@ -131,6 +131,8 @@ _CD64_NUMBER_ENTRIES_TOTAL = 7
_CD64_DIRECTORY_SIZE = 8 _CD64_DIRECTORY_SIZE = 8
_CD64_OFFSET_START_CENTDIR = 9 _CD64_OFFSET_START_CENTDIR = 9
_DD_SIGNATURE = 0x08074b50
_EXTRA_FIELD_STRUCT = struct.Struct('<HH') _EXTRA_FIELD_STRUCT = struct.Struct('<HH')
def _strip_extra(extra, xids): def _strip_extra(extra, xids):
...@@ -1270,9 +1272,9 @@ class ZipFile(object): ...@@ -1270,9 +1272,9 @@ class ZipFile(object):
self.fp.write(bytes) self.fp.write(bytes)
if zinfo.flag_bits & 0x08: if zinfo.flag_bits & 0x08:
# Write CRC and file sizes after the file data # Write CRC and file sizes after the file data
fmt = '<LQQ' if zip64 else '<LLL' fmt = '<LLQQ' if zip64 else '<LLLL'
self.fp.write(struct.pack(fmt, zinfo.CRC, zinfo.compress_size, self.fp.write(struct.pack(fmt, _DD_SIGNATURE, zinfo.CRC,
zinfo.file_size)) zinfo.compress_size, zinfo.file_size))
self.fp.flush() self.fp.flush()
self.filelist.append(zinfo) self.filelist.append(zinfo)
self.NameToInfo[zinfo.filename] = zinfo self.NameToInfo[zinfo.filename] = zinfo
......
...@@ -1295,6 +1295,7 @@ Roger D. Serwy ...@@ -1295,6 +1295,7 @@ Roger D. Serwy
Jerry Seutter Jerry Seutter
Pete Sevander Pete Sevander
Denis Severson Denis Severson
Silas Sewell
Ian Seyer Ian Seyer
Daniel Shahaf Daniel Shahaf
Mark Shannon Mark Shannon
......
Improved compatibility for streamed files in :mod:`zipfile`. Previously an
optional signature was not being written and certain ZIP applications were
not supported. Patch by Silas Sewell.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment