Skip to content

Commit

Permalink
Return from ImagingFill early if image has a zero dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 30, 2022
1 parent 77f6f54 commit 91b01f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tests/test_image.py
Expand Up @@ -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.5)
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
Expand Down
5 changes: 5 additions & 0 deletions src/libImaging/Fill.c
Expand Up @@ -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);
Expand Down

0 comments on commit 91b01f4

Please sign in to comment.