Commit 2bda6a0a authored by Guido van Rossum's avatar Guido van Rossum

Two different changes.

1. Jack Jansen reports that on the Mac, the time may be negative, and
solves this by adding a write32u() function that writes an unsigned
long.

2. On 64-bit platforms the CRC comparison fails; I've fixed this by
casting both values to be compared to "unsigned long" i.e. modulo
0x100000000L.
parent 85364f3b
...@@ -17,6 +17,9 @@ READ, WRITE = 1, 2 ...@@ -17,6 +17,9 @@ READ, WRITE = 1, 2
def write32(output, value): def write32(output, value):
output.write(struct.pack("<l", value)) output.write(struct.pack("<l", value))
def write32u(output, value):
output.write(struct.pack("<L", value))
def read32(input): def read32(input):
return struct.unpack("<l", input.read(4))[0] return struct.unpack("<l", input.read(4))[0]
...@@ -83,7 +86,7 @@ class GzipFile: ...@@ -83,7 +86,7 @@ class GzipFile:
if fname: if fname:
flags = FNAME flags = FNAME
self.fileobj.write(chr(flags)) self.fileobj.write(chr(flags))
write32(self.fileobj, int(time.time())) write32u(self.fileobj, long(time.time()))
self.fileobj.write('\002') self.fileobj.write('\002')
self.fileobj.write('\377') self.fileobj.write('\377')
if fname: if fname:
...@@ -231,7 +234,7 @@ class GzipFile: ...@@ -231,7 +234,7 @@ class GzipFile:
self.fileobj.seek(-8, 1) self.fileobj.seek(-8, 1)
crc32 = read32(self.fileobj) crc32 = read32(self.fileobj)
isize = read32(self.fileobj) isize = read32(self.fileobj)
if crc32 != self.crc: if crc32%0x100000000L != self.crc%0x100000000L:
raise ValueError, "CRC check failed" raise ValueError, "CRC check failed"
elif isize != self.size: elif isize != self.size:
raise ValueError, "Incorrect length of data produced" raise ValueError, "Incorrect length of data produced"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment