mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
Changed overflow check to use PY_SSIZE_T_MAX (#3964)
Changed overflow check to use PY_SSIZE_T_MAX
This commit is contained in:
commit
c36fdf2028
|
@ -4,6 +4,11 @@ from PIL import Image
|
||||||
|
|
||||||
from .helper import PillowTestCase, unittest
|
from .helper import PillowTestCase, unittest
|
||||||
|
|
||||||
|
try:
|
||||||
|
import numpy
|
||||||
|
except ImportError:
|
||||||
|
numpy = None
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform.startswith("win32"), "Win32 does not call map_buffer")
|
@unittest.skipIf(sys.platform.startswith("win32"), "Win32 does not call map_buffer")
|
||||||
class TestMap(PillowTestCase):
|
class TestMap(PillowTestCase):
|
||||||
|
@ -23,3 +28,10 @@ class TestMap(PillowTestCase):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
Image.MAX_IMAGE_PIXELS = max_pixels
|
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)
|
||||||
|
|
|
@ -339,7 +339,7 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
|
||||||
stride = xsize * 4;
|
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");
|
PyErr_SetString(PyExc_MemoryError, "Integer overflow in ysize");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user