From 9188157715f755dfd72cee0bde118fde2210eb53 Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:33:29 +0200 Subject: [PATCH] BUG: fix image look-up table in EncodedStreamObject closes #2124 closes #2110 --- pypdf/filters.py | 3 ++- tests/test_filters.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pypdf/filters.py b/pypdf/filters.py index 303838114..1bc2655a1 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -58,6 +58,7 @@ ArrayObject, DecodedStreamObject, DictionaryObject, + EncodedStreamObject, IndirectObject, NullObject, ) @@ -860,7 +861,7 @@ def bits2byte(data: bytes, size: Tuple[int, int], bits: int) -> bytes: if color_space == "/Indexed": from .generic import TextStringObject - if isinstance(lookup, DecodedStreamObject): + if isinstance(lookup, (EncodedStreamObject, DecodedStreamObject)): lookup = lookup.get_data() if isinstance(lookup, TextStringObject): lookup = lookup.original_bytes diff --git a/tests/test_filters.py b/tests/test_filters.py index 6e145f549..165a81f30 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -585,3 +585,12 @@ def test_jpx_no_spacecode(): with pytest.raises(PdfReadError) as exc: reader.pages[0].images[0] assert exc.value.args[0].startswith("ColorSpace field not found") + + +@pytest.mark.enable_socket() +def test_encodedstream_lookup(): + """From #2124""" + url = "https://github.com/py-pdf/pypdf/files/12455580/10.pdf" + name = "iss2124.pdf" + reader = PdfReader(BytesIO(get_data_from_url(url, name=name))) + reader.pages[12].images[0]