Memory error in Storage.c when accepting negative image size arguments

This commit is contained in:
wiredfool 2016-09-25 10:44:22 +01:00
parent 8693afc502
commit 5d8a0be45a
3 changed files with 16 additions and 0 deletions

BIN
Tests/images/negative_size.ppm Executable file

Binary file not shown.

View File

@ -44,5 +44,17 @@ class TestFilePpm(PillowTestCase):
self.assertRaises(ValueError, lambda: Image.open(path))
def test_neg_ppm(self):
"""test_neg_ppm
Storage.c accepted negative values for xsize, ysize.
open_ppm is a core debugging item that doesn't check any parameters for
sanity.
"""
with self.assertRaises(ValueError):
Image.core.open_ppm('Tests/images/negative_size.ppm')
if __name__ == '__main__':
unittest.main()

View File

@ -406,6 +406,10 @@ ImagingNew(const char* mode, int xsize, int ysize)
} else
bytes = strlen(mode); /* close enough */
if (xsize < 0 || ysize < 0) {
return (Imaging) ImagingError_ValueError("bad image size");
}
if ((int64_t) xsize * (int64_t) ysize <= THRESHOLD / bytes) {
im = ImagingNewBlock(mode, xsize, ysize);
if (im)