mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
Merge pull request #2419 from hugovk/numpy-zero-size
Fix division by zero when creating 0x0 image from numpy array
This commit is contained in:
commit
5544781270
|
@ -2036,7 +2036,7 @@ def _check_size(size):
|
||||||
if len(size) != 2:
|
if len(size) != 2:
|
||||||
raise ValueError("Size must be a tuple of length 2")
|
raise ValueError("Size must be a tuple of length 2")
|
||||||
if size[0] < 0 or size[1] < 0:
|
if size[0] < 0 or size[1] < 0:
|
||||||
raise ValueError("Width and Height must be => 0")
|
raise ValueError("Width and height must be >= 0")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,14 @@ class TestNumpy(PillowTestCase):
|
||||||
|
|
||||||
self.assertEqual(len(im.getdata()), len(arr))
|
self.assertEqual(len(im.getdata()), len(arr))
|
||||||
|
|
||||||
|
def test_zero_size(self):
|
||||||
|
# Shouldn't cause floating point exception
|
||||||
|
# See https://github.com/python-pillow/Pillow/issues/2259
|
||||||
|
|
||||||
|
im = Image.fromarray(numpy.empty((0, 0), dtype=numpy.uint8))
|
||||||
|
|
||||||
|
self.assertEqual(im.size, (0, 0))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
2
map.c
2
map.c
|
@ -342,7 +342,7 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
|
||||||
stride = xsize * 4;
|
stride = xsize * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ysize > INT_MAX / stride) {
|
if (stride > 0 && ysize > INT_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