input parameter filtering

This commit is contained in:
wiredfool 2016-02-04 06:57:57 -08:00
parent ff7962c3be
commit 95a25a0d82
2 changed files with 23 additions and 1 deletions

View File

@ -8,11 +8,29 @@ class TestImagingCoreResize(PillowTestCase):
xsize = 0x100000008 // 4
ysize = 1000 # unimportant
try:
im.im.resize((xsize, ysize), Image.LINEAR) # any resampling filter will do here
# any resampling filter will do here
im.im.resize((xsize, ysize), Image.LINEAR)
self.fail("Resize should raise MemoryError on invalid xsize")
except MemoryError:
self.assertTrue(True, "Should raise MemoryError")
def test_invalid_size(self):
im = hopper()
im.resize((100,100))
self.assertTrue(True, "Should not Crash")
try:
im.resize((-100,100))
self.fail("Resize should raise a value error on x negative size")
except ValueError:
self.assertTrue(True, "Should raise ValueError")
try:
im.resize((100,-100))
self.fail("Resize should raise a value error on y negative size")
except ValueError:
self.assertTrue(True, "Should raise ValueError")
if __name__ == '__main__':
unittest.main()

View File

@ -1532,6 +1532,10 @@ _resize(ImagingObject* self, PyObject* args)
imIn = self->image;
if (xsize < 1 || ysize < 1) {
return ImagingError_ValueError("height and width must be > 0");
}
if (imIn->xsize == xsize && imIn->ysize == ysize) {
imOut = ImagingCopy(imIn);
}