mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
Map.c overflow fixes
This commit is contained in:
parent
5d8a0be45a
commit
c50ebe6459
BIN
Tests/images/l2rgb_read.bmp
Normal file
BIN
Tests/images/l2rgb_read.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 B |
25
Tests/test_map.py
Normal file
25
Tests/test_map.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from helper import PillowTestCase, unittest
|
||||
|
||||
from PIL import Image
|
||||
|
||||
class TestMap(PillowTestCase):
|
||||
def test_overflow(self):
|
||||
# There is the potential to overflow comparisons in map.c
|
||||
# if there are > SIZE_MAX bytes in the image or if
|
||||
# the file encodes an offset that makes
|
||||
# (offset + size(bytes)) > SIZE_MAX
|
||||
|
||||
# Note that this image triggers the decompression bomb warning:
|
||||
max_pixels = Image.MAX_IMAGE_PIXELS
|
||||
Image.MAX_IMAGE_PIXELS = None
|
||||
|
||||
# This image hits the offset test.
|
||||
im = Image.open('Tests/images/l2rgb_read.bmp')
|
||||
with self.assertRaises((ValueError, MemoryError)):
|
||||
im.load()
|
||||
|
||||
Image.MAX_IMAGE_PIXELS = max_pixels
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
10
map.c
10
map.c
|
@ -342,8 +342,18 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
|
|||
stride = xsize * 4;
|
||||
}
|
||||
|
||||
if (ysize > INT_MAX / stride) {
|
||||
PyErr_SetString(PyExc_MemoryError, "Integer overflow in ysize");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = (Py_ssize_t) ysize * stride;
|
||||
|
||||
if (offset > SIZE_MAX - size) {
|
||||
PyErr_SetString(PyExc_MemoryError, "Integer overflow in offset");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* check buffer size */
|
||||
if (PyImaging_GetBuffer(target, &view) < 0)
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue
Block a user