unsupported modes

This commit is contained in:
Alexander 2019-12-01 20:34:05 +03:00
parent 008c1c88e2
commit 1d1f3be27a
2 changed files with 19 additions and 0 deletions

View File

@ -32,6 +32,19 @@ class TestImageReduce(PillowTestCase):
with self.assertRaises(ValueError):
im.reduce((0, 10))
def test_unsupported_modes(self):
im = Image.new("P", (10, 10))
with self.assertRaises(ValueError):
im.reduce(3)
im = Image.new("1", (10, 10))
with self.assertRaises(ValueError):
im.reduce(3)
im = Image.new("I;16", (10, 10))
with self.assertRaises(ValueError):
im.reduce(3)
def get_image(self, mode):
bands = [self.gradients_image]
for _ in ImageMode.getmode(mode).bands[1:]:

View File

@ -963,6 +963,12 @@ ImagingReduce(Imaging imIn, int xscale, int yscale)
ImagingSectionCookie cookie;
Imaging imOut = NULL;
if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0)
return (Imaging) ImagingError_ModeError();
if (imIn->type == IMAGING_TYPE_SPECIAL)
return (Imaging) ImagingError_ModeError();
imOut = ImagingNewDirty(imIn->mode,
(imIn->xsize + xscale - 1) / xscale,
(imIn->ysize + yscale - 1) / yscale);