From 12700436827a06194e4b63a47c5e60585e52be59 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 5 Sep 2024 15:46:54 +1000 Subject: [PATCH] Return early if either width or height is zero --- Tests/test_box_blur.py | 5 +++++ src/libImaging/BoxBlur.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/Tests/test_box_blur.py b/Tests/test_box_blur.py index 1f6ed6127..cb267b204 100644 --- a/Tests/test_box_blur.py +++ b/Tests/test_box_blur.py @@ -71,6 +71,11 @@ def test_color_modes() -> None: box_blur(sample.convert("YCbCr")) +@pytest.mark.parametrize("size", ((0, 1), (1, 0))) +def test_zero_dimension(size: tuple[int, int]) -> None: + assert box_blur(Image.new("L", size)).size == size + + def test_radius_0() -> None: assert_blur( sample, diff --git a/src/libImaging/BoxBlur.c b/src/libImaging/BoxBlur.c index 51cb7e102..ed91541fe 100644 --- a/src/libImaging/BoxBlur.c +++ b/src/libImaging/BoxBlur.c @@ -238,6 +238,9 @@ ImagingBoxBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int n) int i; Imaging imTransposed; + if (imOut->xsize == 0 || imOut->ysize == 0) { + return imOut; + } if (n < 1) { return ImagingError_ValueError("number of passes must be greater than zero"); }