From 91b01f4cc2b1728295c97ac4114f800637c5ead2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 30 Dec 2022 16:48:33 +1100 Subject: [PATCH 1/2] Return from ImagingFill early if image has a zero dimension --- Tests/test_image.py | 5 +++++ src/libImaging/Fill.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Tests/test_image.py b/Tests/test_image.py index a37c90296eb..13c1628125a 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.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 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); From 280330476345c10a3c95ef44b8dba260c6694502 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 31 Dec 2022 13:47:07 +1100 Subject: [PATCH 2/2] Skip timeout checks on slower running valgrind job --- .github/workflows/test-valgrind.yml | 2 +- Tests/test_file_pdf.py | 1 + Tests/test_image.py | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-valgrind.yml b/.github/workflows/test-valgrind.yml index 219189cf208..f8b050f7625 100644 --- a/.github/workflows/test-valgrind.yml +++ b/.github/workflows/test-valgrind.yml @@ -48,5 +48,5 @@ jobs: run: | # The Pillow user in the docker container is UID 1000 sudo chown -R 1000 $GITHUB_WORKSPACE - docker run --name pillow_container -v $GITHUB_WORKSPACE:/Pillow pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }} + docker run --name pillow_container -e "PILLOW_VALGRIND_TEST=true" -v $GITHUB_WORKSPACE:/Pillow pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }} sudo chown -R runner $GITHUB_WORKSPACE diff --git a/Tests/test_file_pdf.py b/Tests/test_file_pdf.py index 9667b6a4aad..5299febe915 100644 --- a/Tests/test_file_pdf.py +++ b/Tests/test_file_pdf.py @@ -286,6 +286,7 @@ def test_pdf_append_to_bytesio(): @pytest.mark.timeout(1) +@pytest.mark.skipif("PILLOW_VALGRIND_TEST" in os.environ, reason="Valgrind is slower") @pytest.mark.parametrize("newline", (b"\r", b"\n")) def test_redos(newline): malicious = b" trailer<<>>" + newline * 3456 diff --git a/Tests/test_image.py b/Tests/test_image.py index 13c1628125a..890769fcd34 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -512,8 +512,11 @@ def test_check_size(self): i = Image.new("RGB", [1, 1]) assert isinstance(i.size, tuple) + @pytest.mark.timeout(0.75) + @pytest.mark.skipif( + "PILLOW_VALGRIND_TEST" in os.environ, reason="Valgrind is slower" + ) @pytest.mark.parametrize("size", ((0, 100000000), (100000000, 0))) - @pytest.mark.timeout(0.5) def test_empty_image(self, size): Image.new("RGB", size)