Commit 4ba3b50b authored by Silas Sewell's avatar Silas Sewell Committed by Serhiy Storchaka

bpo-34472: Add data descriptor signature to zipfile (GH-8871)

This makes streamed zips compatible with MacOS Archive Utility and
other applications.
parent d0f49d2f
...@@ -159,6 +159,8 @@ _CD64_NUMBER_ENTRIES_TOTAL = 7 ...@@ -159,6 +159,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):
...@@ -1118,8 +1120,8 @@ class _ZipWriteFile(io.BufferedIOBase): ...@@ -1118,8 +1120,8 @@ class _ZipWriteFile(io.BufferedIOBase):
# Write updated header info # Write updated header info
if self._zinfo.flag_bits & 0x08: if self._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 self._zip64 else '<LLL' fmt = '<LLQQ' if self._zip64 else '<LLLL'
self._fileobj.write(struct.pack(fmt, self._zinfo.CRC, self._fileobj.write(struct.pack(fmt, _DD_SIGNATURE, self._zinfo.CRC,
self._zinfo.compress_size, self._zinfo.file_size)) self._zinfo.compress_size, self._zinfo.file_size))
self._zipfile.start_dir = self._fileobj.tell() self._zipfile.start_dir = self._fileobj.tell()
else: else:
......
...@@ -1468,6 +1468,7 @@ Roger D. Serwy ...@@ -1468,6 +1468,7 @@ Roger D. Serwy
Jerry Seutter Jerry Seutter
Pete Sevander Pete Sevander
Denis Severson Denis Severson
Silas Sewell
Ian Seyer Ian Seyer
Dmitry Shachnev Dmitry Shachnev
Anish Shah Anish Shah
......
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