Commits

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

  • Participants
  • Parent commits 2edd437
  • Branches stable

Comments (0)

Files changed (1)

File sphinx/util/png.py

         # 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: