mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Memory error in Storage.c when accepting negative image size arguments
This commit is contained in:
parent
8693afc502
commit
5d8a0be45a
BIN
Tests/images/negative_size.ppm
Executable file
BIN
Tests/images/negative_size.ppm
Executable file
Binary file not shown.
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user