When writing files to zipfile, reset timestamp if it doesn't fit in 1980's vintage storage structures

This commit is contained in:
Kovid Goyal 2011-06-05 13:38:50 -06:00
parent 06c76ae36d
commit 70e0cd6ba4

View File

@ -340,7 +340,14 @@ class ZipInfo (object):
"""Return the per-file header as a string.""" """Return the per-file header as a string."""
dt = self.date_time dt = self.date_time
dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2]
# Added by Kovid to reset timestamp to default if it overflows the DOS
# limits
if dosdate > 0xffff or dosdate < 0:
dosdate = 0
dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2) dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2)
if dostime > 0xffff or dostime < 0:
dostime = 0
if self.flag_bits & 0x08: if self.flag_bits & 0x08:
# Set these to zero because we write them after the file data # Set these to zero because we write them after the file data
CRC = compress_size = file_size = 0 CRC = compress_size = file_size = 0