From ea605b9589f2872924509a79e826cf1481e9fdaa Mon Sep 17 00:00:00 2001 From: Marcin Wojdyr Date: Mon, 6 May 2013 22:49:36 +0100 Subject: [PATCH] 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 --- sphinx/util/png.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/util/png.py b/sphinx/util/png.py index 50c72efdc..fd0cbab9d 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: