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

Skip to content

Commit 95bdd0b

Browse files
committed
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.
1 parent 65f685b commit 95bdd0b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/gzip.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
def write32(output, value):
1818
output.write(struct.pack("<l", value))
1919

20+
def write32u(output, value):
21+
output.write(struct.pack("<L", value))
22+
2023
def read32(input):
2124
return struct.unpack("<l", input.read(4))[0]
2225

@@ -83,7 +86,7 @@ def _write_gzip_header(self):
8386
if fname:
8487
flags = FNAME
8588
self.fileobj.write(chr(flags))
86-
write32(self.fileobj, int(time.time()))
89+
write32u(self.fileobj, long(time.time()))
8790
self.fileobj.write('\002')
8891
self.fileobj.write('\377')
8992
if fname:
@@ -231,7 +234,7 @@ def _read_eof(self):
231234
self.fileobj.seek(-8, 1)
232235
crc32 = read32(self.fileobj)
233236
isize = read32(self.fileobj)
234-
if crc32 != self.crc:
237+
if crc32%0x100000000L != self.crc%0x100000000L:
235238
raise ValueError, "CRC check failed"
236239
elif isize != self.size:
237240
raise ValueError, "Incorrect length of data produced"

0 commit comments

Comments
 (0)