Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix image look-up table in EncodedStreamObject #2128

Merged
merged 3 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pypdf/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
ArrayObject,
DecodedStreamObject,
DictionaryObject,
EncodedStreamObject,
IndirectObject,
NullObject,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -904,7 +905,7 @@ def bits2byte(data: bytes, size: Tuple[int, int], bits: int) -> bytes:
f"Invalid Lookup Table in {obj_as_text}", __name__
)
lookup = None
if mode == "L":
elif mode == "L":
# gray lookup does not work : it is converted to a similar RGB lookup
lookup = b"".join([bytes([b, b, b]) for b in lookup])
mode = "RGB"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Loading