Skip to content

Commit b751ca2

Browse files
ROB: Fail with explicit exception when image mode is an empty array (#3500)
Closes #3499.
1 parent e13a1e0 commit b751ca2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pypdf/_xobj_image_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def _get_imagemode(
6464
raise PdfReadError(
6565
"Cannot interpret color space", color_space
6666
) # pragma: no cover
67+
elif not color_space:
68+
return "", False
6769
elif color_space[0].startswith("/Cal"): # /CalRGB and /CalGray
6870
color_space_str = "/Device" + color_space[0][4:]
6971
elif color_space[0] == "/ICCBased":

tests/test_xobject_image_helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,14 @@ def test_get_mode_and_invert_color():
160160
page = reader.pages[12]
161161
for _name, image in page.images.items(): # noqa: PERF102
162162
image.image.load()
163+
164+
165+
@pytest.mark.enable_socket
166+
def test_get_imagemode__empty_array():
167+
url = "https://github.com/user-attachments/files/23050451/poc.pdf"
168+
name = "issue3499.pdf"
169+
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
170+
page = reader.pages[0]
171+
172+
with pytest.raises(expected_exception=PdfReadError, match=r"^ColorSpace field not found in .+"):
173+
page.images[0].image.load()

0 commit comments

Comments
 (0)