From da6ce58dd5ac109485af45878fca6bfd265b43e9 Mon Sep 17 00:00:00 2001 From: Daniel Hillier Date: Tue, 29 Oct 2019 18:24:18 +1100 Subject: bpo-36993: Improve error reporting for zipfiles with bad zip64 extra data. (GH-14656) --- Lib/test/test_zipfile.py | 222 +++++++++++++++++++++ Lib/zipfile.py | 12 ++ .../2019-07-09-05-44-39.bpo-36993.4javqu.rst | 2 + 3 files changed, 236 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-07-09-05-44-39.bpo-36993.4javqu.rst diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 6e1291e..1e1854b 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -1,6 +1,7 @@ import contextlib import importlib.util import io +import itertools import os import pathlib import posixpath @@ -824,6 +825,227 @@ class StoredTestZip64InSmallFiles(AbstractTestZip64InSmallFiles, zinfo = zipfp.getinfo("strfile") self.assertEqual(zinfo.extra, extra) + def make_zip64_file( + self, file_size_64_set=False, file_size_extra=False, + compress_size_64_set=False, compress_size_extra=False, + header_offset_64_set=False, header_offset_extra=False, + ): + """Generate bytes sequence for a zip with (incomplete) zip64 data. + + The actual values (not the zip 64 0xffffffff values) stored in the file + are: + file_size: 8 + compress_size: 8 + header_offset: 0 + """ + actual_size = 8 + actual_header_offset = 0 + local_zip64_fields = [] + central_zip64_fields = [] + + file_size = actual_size + if file_size_64_set: + file_size = 0xffffffff + if file_size_extra: + local_zip64_fields.append(actual_size) + central_zip64_fields.append(actual_size) + file_size = struct.pack("