From 1859bbc109fdf276f9bbcf8fb831515cc1a2c22d Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 30 Sep 2026 12:03:37 +0300 Subject: [PATCH] fromarrow: Use correct check for ImagingCore falsity By virtue of `image_length` (the `len` handler for `ImagingCore`s) returning the product of the image's dimensions, if either dimension is zero, the `ImagingCore` evaluates falsy. `if im` isn't then the correct check for `None`-ness. --- Tests/test_pyarrow.py | 6 ++++++ src/PIL/Image.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/test_pyarrow.py b/Tests/test_pyarrow.py index d111f18f59d..61d651b08be 100644 --- a/Tests/test_pyarrow.py +++ b/Tests/test_pyarrow.py @@ -283,3 +283,9 @@ def test_image_metadata(mode: str, metadata: list[str]) -> None: assert "bands" in parsed_metadata assert parsed_metadata["bands"] == metadata + + +def test_zero_dimension() -> None: + array = pyarrow.array([], type=pyarrow.uint8()) + assert Image.fromarrow(array, "L", (0, 7)).size == (0, 7) + assert Image.fromarrow(array, "L", (7, 0)).size == (7, 0) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index bde53152bbb..fae0fcffcc9 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -3516,7 +3516,7 @@ def fromarrow( schema_capsule, array_capsule = obj.__arrow_c_array__() _im = core.new_arrow(mode, size, schema_capsule, array_capsule) - if _im: + if _im is not None: return Image()._new(_im) msg = "new_arrow returned None without an exception"