From 0a9055da2df66c80eabfa3ef6d35a90953a5b84d Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Thu, 27 Jul 2023 21:35:24 +0200 Subject: [PATCH] BUG: Handle single element ColorSpace list (#2026) Fixes #2023 --- pypdf/filters.py | 2 ++ tests/test_filters.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/pypdf/filters.py b/pypdf/filters.py index e6f311529..78e5a9f71 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -860,6 +860,8 @@ def _handle_jpx( data = data.encode() colors = x_object_obj.get("/Colors", 1) color_space: Any = x_object_obj.get("/ColorSpace", NullObject()).get_object() + if isinstance(color_space, list) and len(color_space) == 1: + color_space = color_space[0].get_object() if ( IA.COLOR_SPACE in x_object_obj and x_object_obj[IA.COLOR_SPACE] == ColorSpaces.DEVICE_RGB diff --git a/tests/test_filters.py b/tests/test_filters.py index 76f49430e..86d46bb4d 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -553,3 +553,12 @@ def test_gray_devicen_cmyk(): diff = ImageChops.difference(data.image, refimg) d = sqrt(sum([(a * a) for a in diff.getdata()])) / (diff.size[0] * diff.size[1]) assert d < 0.001 + + +@pytest.mark.enable_socket() +def test_singleton_device(): + """From #2023""" + url = "https://github.com/py-pdf/pypdf/files/12177287/tt.pdf" + name = "pypdf_with_arr_deviceRGB.pdf" + reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name))) + reader.pages[0].images[0]