Changed overflow check to use PY_SSIZE_T_MAX

This commit is contained in:
Andrew Murray 2019-07-11 21:12:36 +10:00
parent 1ab5670eb1
commit 66ad3cb461
2 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,11 @@ from PIL import Image
from .helper import PillowTestCase, unittest
try:
import numpy
except ImportError:
numpy = None
@unittest.skipIf(sys.platform.startswith("win32"), "Win32 does not call map_buffer")
class TestMap(PillowTestCase):
@ -23,3 +28,10 @@ class TestMap(PillowTestCase):
im.load()
Image.MAX_IMAGE_PIXELS = max_pixels
@unittest.skipIf(sys.maxsize <= 2 ** 32, "requires 64-bit system")
@unittest.skipIf(numpy is None, "Numpy is not installed")
def test_ysize(self):
# Should not raise 'Integer overflow in ysize'
arr = numpy.zeros((46341, 46341), dtype=numpy.uint8)
Image.fromarray(arr)

View File

@ -339,7 +339,7 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
stride = xsize * 4;
}
if (stride > 0 && ysize > INT_MAX / stride) {
if (stride > 0 && ysize > PY_SSIZE_T_MAX / stride) {
PyErr_SetString(PyExc_MemoryError, "Integer overflow in ysize");
return NULL;
}