From 1d1f3be27acd50fc4b8184707d7f6223a3fde97f Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 1 Dec 2019 20:34:05 +0300 Subject: [PATCH] unsupported modes --- Tests/test_image_reduce.py | 13 +++++++++++++ src/libImaging/Reduce.c | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/Tests/test_image_reduce.py b/Tests/test_image_reduce.py index a07d9c98c..bfa01d2bd 100644 --- a/Tests/test_image_reduce.py +++ b/Tests/test_image_reduce.py @@ -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:]: diff --git a/src/libImaging/Reduce.c b/src/libImaging/Reduce.c index 403e0bf68..630216ccc 100644 --- a/src/libImaging/Reduce.c +++ b/src/libImaging/Reduce.c @@ -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);