GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — zipfile regression: When writing a zip64 entry to an unseekable file, the local file header compressed/uncompressed fields are not set to 0 · Issue #106218 · python/cpython Closed Labels type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportWhen creating a zip file with a zip64 entry in a streaming way (unseekable file), my understanding from the spec is that the headers should be set up so that:
From initial testing, it seems like this is all that's needed to fix the issue: --- zipfile.py 2023-06-08 22:29:05.000000000 -0400 +++ zipfile2.py 2023-06-28 17:50:45.841709476 -0400 @@ -463,8 +463,9 @@ fmt = '<HHQQ' extra = extra + struct.pack(fmt, 1, struct.calcsize(fmt)-4, file_size, compress_size) - file_size = 0xffffffff - compress_size = 0xffffffff + if not (self.flag_bits & _MASK_USE_DATA_DESCRIPTOR): + file_size = 0xffffffff + compress_size = 0xffffffff min_version = ZIP64_VERSION if self.compress_type == ZIP_BZIP2: To reproduceimport zipfile class UnseekableFile: def __init__(self, fp): self.fp = fp def write(self, data): return self.fp.write(data) def flush(self): self.fp.flush() with open('test.zip', 'wb') as f_raw: with zipfile.ZipFile(UnseekableFile(f_raw), 'w') as z: with z.open('foobar', 'w', force_zip64=True) as f: f.write(b'Hello, world!') The resulting file looks like this, as reported by zipdetails (green=good, red=problematic). 0000 LOCAL HEADER #1 04034B50 0004 Extract Zip Spec 2D '4.5' 0005 Extract OS 00 'MS-DOS' +0006 General Purpose Flag 0008 + [Bit 3] 1 'Streamed' 0008 Compression Method 0000 'Stored' 000A Last Mod Time 00210000 'Mon Dec 31 19:00:00 1979' +000E CRC 00000000 -0012 Compressed Length FFFFFFFF -0016 Uncompressed Length FFFFFFFF 001A Filename Length 0006 001C Extra Length 0014 001E Filename 'foobar' +0024 Extra ID #0001 0001 'ZIP64' +0026 Length 0010 +0028 Uncompressed Size 0000000000000000 +0030 Compressed Size 0000000000000000 0038 PAYLOAD Hello, world! +0045 STREAMING DATA HEADER 08074B50 +0049 CRC EBE6C6E6 +004D Compressed Length 000000000000000D +0055 Uncompressed Length 000000000000000D 005D CENTRAL HEADER #1 02014B50 0061 Created Zip Spec 2D '4.5' 0062 Created OS 03 'Unix' 0063 Extract Zip Spec 2D '4.5' 0064 Extract OS 00 'MS-DOS' 0065 General Purpose Flag 0008 [Bit 3] 1 'Streamed' 0067 Compression Method 0000 'Stored' 0069 Last Mod Time 00210000 'Mon Dec 31 19:00:00 1979' 006D CRC EBE6C6E6 0071 Compressed Length 0000000D 0075 Uncompressed Length 0000000D 0079 Filename Length 0006 007B Extra Length 0000 007D Comment Length 0000 007F Disk Start 0000 0081 Int File Attributes 0000 [Bit 0] 0 'Binary Data' 0083 Ext File Attributes 01800000 0087 Local Header Offset 00000000 008B Filename 'foobar' 0091 END CENTRAL HEADER 06054B50 0095 Number of this disk 0000 0097 Central Dir Disk no 0000 0099 Entries in this disk 0001 009B Total Entries 0001 009D Size of Central Dir 00000034 00A1 Offset to Central Dir 0000005D 00A5 Comment Length 0000 Done Your environment
Activity
MetadataMetadataAssigneesLabelstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |