Skip to content

Commit

Permalink
Changed overflow check to use PY_SSIZE_T_MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 16, 2019
1 parent 1ab5670 commit 66ad3cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Tests/test_map.py
Expand Up @@ -4,6 +4,11 @@

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):
Expand All @@ -23,3 +28,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)
2 changes: 1 addition & 1 deletion src/map.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 66ad3cb

Please sign in to comment.