[Python-checkins] bpo-34472: Add data descriptor signature to zipfile (GH-8871)
Serhiy Storchaka
webhook-mailer at python.org
Tue Sep 18 13:00:09 EDT 2018
https://github.com/python/cpython/commit/4ba3b50bfe6d50cd82d208023ea23e203ab50589
commit: 4ba3b50bfe6d50cd82d208023ea23e203ab50589
branch: master
author: Silas Sewell <silas at sewell.org>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018-09-18T20:00:05+03:00
summary:
bpo-34472: Add data descriptor signature to zipfile (GH-8871)
This makes streamed zips compatible with MacOS Archive Utility and
other applications.
files:
A Misc/NEWS.d/next/Library/2018-08-23-09-25-08.bpo-34472.cGyYrO.rst
M Lib/zipfile.py
M Misc/ACKS
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 89df90b25209..4a6b40ee441c 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -159,6 +159,8 @@ class LargeZipFile(Exception):
_CD64_DIRECTORY_SIZE = 8
_CD64_OFFSET_START_CENTDIR = 9
+_DD_SIGNATURE = 0x08074b50
+
_EXTRA_FIELD_STRUCT = struct.Struct('<HH')
def _strip_extra(extra, xids):
@@ -1118,8 +1120,8 @@ def close(self):
# Write updated header info
if self._zinfo.flag_bits & 0x08:
# Write CRC and file sizes after the file data
- fmt = '<LQQ' if self._zip64 else '<LLL'
- self._fileobj.write(struct.pack(fmt, self._zinfo.CRC,
+ fmt = '<LLQQ' if self._zip64 else '<LLLL'
+ self._fileobj.write(struct.pack(fmt, _DD_SIGNATURE, self._zinfo.CRC,
self._zinfo.compress_size, self._zinfo.file_size))
self._zipfile.start_dir = self._fileobj.tell()
else:
diff --git a/Misc/ACKS b/Misc/ACKS
index a29ff6020bbf..96563f62a1a8 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1468,6 +1468,7 @@ Roger D. Serwy
Jerry Seutter
Pete Sevander
Denis Severson
+Silas Sewell
Ian Seyer
Dmitry Shachnev
Anish Shah
diff --git a/Misc/NEWS.d/next/Library/2018-08-23-09-25-08.bpo-34472.cGyYrO.rst b/Misc/NEWS.d/next/Library/2018-08-23-09-25-08.bpo-34472.cGyYrO.rst
new file mode 100644
index 000000000000..208ec0bf7431
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-08-23-09-25-08.bpo-34472.cGyYrO.rst
@@ -0,0 +1,3 @@
+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.
More information about the Python-checkins
mailing list