]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34472: Add data descriptor signature to zipfile (GH-8871) (GH-9398)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 22 Sep 2018 18:02:53 +0000 (11:02 -0700)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 22 Sep 2018 18:02:53 +0000 (21:02 +0300)
This makes streamed zips compatible with MacOS Archive Utility and
other applications.
(cherry picked from commit 4ba3b50bfe6d50cd82d208023ea23e203ab50589)

Co-authored-by: Silas Sewell <silas@sewell.org>
Lib/zipfile.py
Misc/ACKS
Misc/NEWS.d/next/Library/2018-08-23-09-25-08.bpo-34472.cGyYrO.rst [new file with mode: 0644]

index bc757a37b5c4511a47bf9ec8b0d4ec6447917037..5bb35870a68970c9b689805295676d63aaa02729 100644 (file)
@@ -164,6 +164,8 @@ _CD64_NUMBER_ENTRIES_TOTAL = 7
 _CD64_DIRECTORY_SIZE = 8
 _CD64_OFFSET_START_CENTDIR = 9
 
+_DD_SIGNATURE = 0x08074b50
+
 _EXTRA_FIELD_STRUCT = struct.Struct('<HH')
 
 def _strip_extra(extra, xids):
@@ -1031,8 +1033,8 @@ class _ZipWriteFile(io.BufferedIOBase):
         # 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:
index bd8a5fb81f0f320eca0a878d84e8b64de24343ea..94731b493c51dd0d9befb625abd703a20a4381a9 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1419,6 +1419,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 (file)
index 0000000..208ec0b
--- /dev/null
@@ -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.