Marcin Wojdyr committed fe55b25

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

Comments (0)

Files changed (1)


         # 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.