diff --git a/Tests/test_map.py b/Tests/test_map.py index 33920f118cf..44e5fe6fafe 100644 --- a/Tests/test_map.py +++ b/Tests/test_map.py @@ -3,6 +3,11 @@ from PIL import Image +try: + import numpy +except ImportError: + numpy = None + @unittest.skipIf(sys.platform.startswith("win32"), "Win32 does not call map_buffer") class TestMap(PillowTestCase): @@ -22,3 +27,10 @@ def test_overflow(self): 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) diff --git a/src/map.c b/src/map.c index 76b3160129f..099bb4b3ef3 100644 --- a/src/map.c +++ b/src/map.c @@ -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; }