Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ def _check_size(size):
if len(size) != 2:
raise ValueError("Size must be a tuple of length 2")
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

Expand Down
8 changes: 8 additions & 0 deletions Tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ def test_putdata(self):

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__':
unittest.main()
4 changes: 2 additions & 2 deletions map.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
stride = xsize * 4;
}

if (ysize > INT_MAX / stride) {
if (stride > 0 && ysize > INT_MAX / stride) {
PyErr_SetString(PyExc_MemoryError, "Integer overflow in ysize");
return NULL;
}
Expand All @@ -352,7 +352,7 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
if (offset > PY_SSIZE_T_MAX - size) {
PyErr_SetString(PyExc_MemoryError, "Integer overflow in offset");
return NULL;
}
}

/* check buffer size */
if (PyImaging_GetBuffer(target, &view) < 0)
Expand Down