Closes #982: Avoid crash when writing PNG file using Python 3.

binascii.crc32() has changed in version 3.0.
In Py2 it returns value in the range [-2**31, 2**31-1],
in Py3 in [0, 2**32-1].

This change made write_png_depth() crash with:
struct.error: 'i' format requires -2147483648 <= number <= 2147483647
This commit is contained in:
Marcin Wojdyr 2013-05-06 22:49:36 +01:00
parent 926cd01168
commit ea605b9589

View File

@ -51,7 +51,8 @@ def write_png_depth(filename, depth):
# overwrite it with the depth chunk
f.write(DEPTH_CHUNK_LEN + DEPTH_CHUNK_START + data)
# calculate the checksum over chunk name and data
f.write(struct.pack('!i', binascii.crc32(DEPTH_CHUNK_START + data)))
crc = binascii.crc32(DEPTH_CHUNK_START + data) & 0xffffffff
f.write(struct.pack('!I', crc))
# replace the IEND chunk
f.write(IEND_CHUNK)
finally: