Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed overflow check to use PY_SSIZE_T_MAX #3964

Merged
merged 1 commit into from Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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