Closed
Description
Bug report
When forcing a small file to be added to a zipfile.Zipfile
object with zip64 extensions when it doesn't need it, a Zip64 extra record is added to the resulting file, but the minimum version and filesize information are not updated to reflect this.
An example of this issue in the wild: pR0Ps/zipstream-ng#13
To reproduce:
Create the file:
import zipfile
with zipfile.ZipFile("out.zip", mode="w", allowZip64=True) as zf:
with zf.open("text.txt", mode="w", force_zip64=True) as zi:
zi.write(b"some data")
Using zipdetails to parse information from the resulting file (red lines are incorrect):
0000 LOCAL HEADER #1 04034B50
-0004 Extract Zip Spec 14 '2.0'
0005 Extract OS 00 'MS-DOS'
0006 General Purpose Flag 0000
0008 Compression Method 0000 'Stored'
000A Last Mod Time 00210000 'Mon Dec 31 19:00:00 1979'
000E CRC D9C2E91E
-0012 Compressed Length 00000009
-0016 Uncompressed Length 00000009
001A Filename Length 0008
001C Extra Length 0014
001E Filename 'text.txt'
0026 Extra ID #0001 0001 'ZIP64'
0028 Length 0010
002A Uncompressed Size 0000000000000009
0032 Compressed Size 0000000000000009
003A PAYLOAD some data
0043 CENTRAL HEADER #1 02014B50
-0047 Created Zip Spec 14 '2.0'
0048 Created OS 03 'Unix'
-0049 Extract Zip Spec 14 '2.0'
004A Extract OS 00 'MS-DOS'
004B General Purpose Flag 0000
004D Compression Method 0000 'Stored'
004F Last Mod Time 00210000 'Mon Dec 31 19:00:00 1979'
0053 CRC D9C2E91E
0057 Compressed Length 00000009
005B Uncompressed Length 00000009
005F Filename Length 0008
0061 Extra Length 0000
0063 Comment Length 0000
0065 Disk Start 0000
0067 Int File Attributes 0000
[Bit 0] 0 'Binary Data'
0069 Ext File Attributes 01800000
006D Local Header Offset 00000000
0071 Filename 'text.txt'
0079 END CENTRAL HEADER 06054B50
007D Number of this disk 0000
007F Central Dir Disk no 0000
0081 Entries in this disk 0001
0083 Total Entries 0001
0085 Size of Central Dir 00000036
0089 Offset to Central Dir 00000043
008D Comment Length 0000
In this case, the Extract Zip Spec should be 0x2D
(zipfile.ZIP64_VERSION
) and the Compressed/Uncompressed Lengths should both be 0xFFFFFFFF
in order to defer to the lengths in the Zip64 record.
Your environment
- CPython versions tested on: 3.12.0
- Operating system and architecture: macOS Mojave (x86)
Linked PRs
Metadata
Metadata
Assignees
Labels
only security fixesonly security fixesAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done