diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-22 17:48:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-22 17:48:23 (GMT) |
commit | 6ec298114855b648a1f5fc4188ea3686a9d77fb3 (patch) | |
tree | a89f690ca45f1e8e07dc59f7e8d5830dbe4af2e0 | |
parent | fef3a92be9e58aa4175daae98422f9b50b75ff84 (diff) | |
download | cpython-6ec298114855b648a1f5fc4188ea3686a9d77fb3.zip cpython-6ec298114855b648a1f5fc4188ea3686a9d77fb3.tar.gz cpython-6ec298114855b648a1f5fc4188ea3686a9d77fb3.tar.bz2 |
[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 4ba3b50bfe6d50cd82d208023ea23e203ab50589)
Co-authored-by: Silas Sewell <silas@sewell.org>
-rw-r--r-- | Lib/zipfile.py | 8 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2018-08-23-09-25-08.bpo-34472.cGyYrO.rst | 3 |
3 files changed, 9 insertions, 3 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 0f890ac..991a0ad 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -131,6 +131,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): @@ -1270,9 +1272,9 @@ class ZipFile(object): self.fp.write(bytes) if zinfo.flag_bits & 0x08: # Write CRC and file sizes after the file data - fmt = '<LQQ' if zip64 else '<LLL' - self.fp.write(struct.pack(fmt, zinfo.CRC, zinfo.compress_size, - zinfo.file_size)) + fmt = '<LLQQ' if zip64 else '<LLLL' + self.fp.write(struct.pack(fmt, _DD_SIGNATURE, zinfo.CRC, + zinfo.compress_size, zinfo.file_size)) self.fp.flush() self.filelist.append(zinfo) self.NameToInfo[zinfo.filename] = zinfo @@ -1295,6 +1295,7 @@ Roger D. Serwy Jerry Seutter Pete Sevander Denis Severson +Silas Sewell Ian Seyer Daniel Shahaf Mark Shannon 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 0000000..208ec0b --- /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. |