Bug report
Bug description:
1. force_zip64=True is ignored when writing central directory
Zip64 extra field in the central directory ignores force_zip64=True. It only generates zip64 when the file size, compressed size, or header offset really exceeds zipfile.ZIP64_LIMIT.
import io
import zipfile
fh = io.BytesIO()
with zipfile.ZipFile(fh, 'w') as zh:
with zh.open('strfile', 'w', force_zip64=True) as zi:
pass
fh.seek(0)
with zipfile.ZipFile(fh, 'r') as zh:
zinfo = zh.getinfo('strfile')
print(zinfo.extra)
The result is b'', while it should be b'\x01\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'.
2. The local file entry may generate duplicated Zip64 extra fields
The local file entry may contain duplicated Zip64 extra fields if its ZipInfo already has one in the extra attribute.
import io
import struct
import zipfile
fh = io.BytesIO()
with zipfile.ZipFile(fh, 'w') as zh:
zinfo = zipfile.ZipInfo('strfile')
zinfo.extra = (
b'\x01\x00\x10\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00'
)
with zh.open(zinfo, 'w', force_zip64=True) as zi:
pass
fh.seek(0)
fh.seek(zinfo.header_offset)
entry = fh.read(zh.start_dir - zinfo.header_offset - zinfo.compress_size)
header = struct.unpack_from(zipfile.structFileHeader, entry)
extra_bytes = entry[-header[zipfile._FH_EXTRA_FIELD_LENGTH]:]
print(extra_bytes)
The result is double b'\x01\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', while only one should exist.
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
1.
force_zip64=Trueis ignored when writing central directoryZip64 extra field in the central directory ignores
force_zip64=True. It only generates zip64 when the file size, compressed size, or header offset really exceedszipfile.ZIP64_LIMIT.The result is
b'', while it should beb'\x01\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'.2. The local file entry may generate duplicated Zip64 extra fields
The local file entry may contain duplicated Zip64 extra fields if its
ZipInfoalready has one in theextraattribute.The result is double
b'\x01\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', while only one should exist.CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs
force_zip64not honored when writing central directory #152493