Merge pull request #6842 from radarhere/zero

Return from ImagingFill early if image has a zero dimension
This commit is contained in:
Hugo van Kemenade 2022-12-31 13:23:12 +02:00 committed by GitHub
commit 7b0008bb82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -48,5 +48,5 @@ jobs:
run: | run: |
# The Pillow user in the docker container is UID 1000 # The Pillow user in the docker container is UID 1000
sudo chown -R 1000 $GITHUB_WORKSPACE 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 sudo chown -R runner $GITHUB_WORKSPACE

View File

@ -286,6 +286,7 @@ def test_pdf_append_to_bytesio():
@pytest.mark.timeout(1) @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")) @pytest.mark.parametrize("newline", (b"\r", b"\n"))
def test_redos(newline): def test_redos(newline):
malicious = b" trailer<<>>" + newline * 3456 malicious = b" trailer<<>>" + newline * 3456

View File

@ -512,6 +512,14 @@ class TestImage:
i = Image.new("RGB", [1, 1]) i = Image.new("RGB", [1, 1])
assert isinstance(i.size, tuple) 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)))
def test_empty_image(self, size):
Image.new("RGB", size)
def test_storage_neg(self): def test_storage_neg(self):
# Storage.c accepted negative values for xsize, ysize. Was # Storage.c accepted negative values for xsize, ysize. Was
# test_neg_ppm, but the core function for that has been # test_neg_ppm, but the core function for that has been

View File

@ -24,6 +24,11 @@ ImagingFill(Imaging im, const void *colour) {
int x, y; int x, y;
ImagingSectionCookie cookie; 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) { if (im->type == IMAGING_TYPE_SPECIAL) {
/* use generic API */ /* use generic API */
ImagingAccess access = ImagingAccessNew(im); ImagingAccess access = ImagingAccessNew(im);