Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restore ZipInfo.FileHeader zip64=None default to maintain backwards c…
…ompatibility in the API.

Code within this module always passes an explicit zip64, so the overall bug fix remains valid. We just don't want to break existing user code constructing their own ZipInfo objects and calling zi.FileHeader themselves for whatever reasons.  _(hopefully rare, but it isn't a protected or private API so we can't make assumptions)_
  • Loading branch information
gpshead authored May 16, 2023
commit ee7c78bd6f183e346cc4bdaa427043aaae9da874
13 changes: 11 additions & 2 deletions Lib/zipfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,13 @@ def __repr__(self):
result.append('>')
return ''.join(result)

def FileHeader(self, zip64=False):
"""Return the per-file header as a bytes object."""
def FileHeader(self, zip64=None):
"""Return the per-file header as a bytes object.

When the optional zip64 arg is None rather than a bool, we will
decide based upon the file_size and compress_size, if known,
False otherwise.
"""
dt = self.date_time
dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2]
dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2)
Expand All @@ -455,6 +460,10 @@ def FileHeader(self, zip64=False):
extra = self.extra

min_version = 0
if zip64 is None:
# We always explicitly pass zip64 within this module.... This
# remains for anyone using ZipInfo.FileHeader as a public API.
zip64 = file_size > ZIP64_LIMIT or compress_size > ZIP64_LIMIT
if zip64:
fmt = '<HHQQ'
extra = extra + struct.pack(fmt,
Expand Down