diff --git a/Tests/test_image.py b/Tests/test_image.py index a37c90296eb..5bca4eebc8e 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -512,6 +512,11 @@ def test_check_size(self): i = Image.new("RGB", [1, 1]) assert isinstance(i.size, tuple) + @pytest.mark.parametrize("size", ((0, 100000000), (100000000, 0))) + @pytest.mark.timeout(0.1) + def test_empty_image(self, size): + Image.new("RGB", size) + def test_storage_neg(self): # Storage.c accepted negative values for xsize, ysize. Was # test_neg_ppm, but the core function for that has been diff --git a/src/libImaging/Fill.c b/src/libImaging/Fill.c index f7206022843..5b6bfb89cd8 100644 --- a/src/libImaging/Fill.c +++ b/src/libImaging/Fill.c @@ -24,6 +24,11 @@ ImagingFill(Imaging im, const void *colour) { int x, y; ImagingSectionCookie cookie; + /* 0-width or 0-height image. No need to do anything */ + if (!im->linesize || !im->ysize) { + return im; + } + if (im->type == IMAGING_TYPE_SPECIAL) { /* use generic API */ ImagingAccess access = ImagingAccessNew(im);