summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
authorMarcin Wojdyr <wojdyr@gmail.com>2013-05-06 22:49:36 +0100
committerMarcin Wojdyr <wojdyr@gmail.com>2013-05-06 22:49:36 +0100
commit404946bf8d70a002342a22975a8ada388491d788 (patch)
tree0ae2526b0bec5570970d68949134274972106060 /sphinx/util
parent0c198c902765d2bf1d9fdab2a3657d96226a6483 (diff)
downloadsphinx-404946bf8d70a002342a22975a8ada388491d788.tar.gz
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
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/png.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/sphinx/util/png.py b/sphinx/util/png.py
index 50c72efd..fd0cbab9 100644
--- a/sphinx/util/png.py
+++ b/sphinx/util/png.py
@@ -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: