Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pubpub-zz committed May 4, 2024
1 parent b449664 commit 44b41a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 19 additions & 11 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import re
import sys
from io import BytesIO
from math import ceil
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -1159,29 +1160,34 @@ def _read_inline_image(self, stream: StreamType) -> Dict[str, Any]:
tmp = stream.read(3)
assert tmp[:2] == b"ID"
filtr = settings.get("/F", "not set")
savpos = stream.tell()
# print("inline", stream.tell(),filtr,"*",settings)
if isinstance(filtr, list):
filtr = filtr[0] # used forencoding
if filtr == "AHx":
if filtr == "AHx" or "ASCIIHexDecode" in filtr:
data = extract_inline_AHex(stream)

Check warning on line 1168 in pypdf/generic/_data_structures.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_data_structures.py#L1168

Added line #L1168 was not covered by tests
elif filtr == "A85":
elif filtr == "A85" or "ASCII85Decode" in filtr:
data = extract_inline_A85(stream)

Check warning on line 1170 in pypdf/generic/_data_structures.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_data_structures.py#L1170

Added line #L1170 was not covered by tests
elif filtr == "RL":
elif filtr == "RL" or "RunLengthDecode" in filtr:
data = extract_inline_RL(stream)

Check warning on line 1172 in pypdf/generic/_data_structures.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_data_structures.py#L1172

Added line #L1172 was not covered by tests
elif filtr == "DCT":
elif filtr == "DCT" or "DCTDecode" in filtr:
data = extract_inline_DCT(stream)

Check warning on line 1174 in pypdf/generic/_data_structures.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_data_structures.py#L1174

Added line #L1174 was not covered by tests
elif filtr == "not set":
cs = settings["/CS"]
if cs == "/I" or cs == "/G":
cs = settings.get("/CS", "")
if cs == "/I" or cs == "/G" or cs == "/Indexed" or cs == "/DeviceGray":
lcs = 1
elif cs == "/RGB":
elif "RGB" in cs:
lcs = 3
elif cs == "/CMYK":
elif "CMYK" in cs:
lcs = 4
else:
raise PdfReadError("Invalid CS value:", cs)
bits = settings.get("/BPC", -1)
if bits > 0:
lcs = bits / 8.0
else:
raise PdfReadError("Invalid CS value:", cs)

Check warning on line 1188 in pypdf/generic/_data_structures.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_data_structures.py#L1188

Added line #L1188 was not covered by tests
data = stream.read(
cast(int, settings["/W"]) * cast(int, settings["/H"]) * lcs
ceil(cast(int, settings["/W"]) * lcs) * cast(int, settings["/H"])
)
ei = read_non_whitespace(stream)
ei += stream.read(1)
Expand All @@ -1190,7 +1196,9 @@ def _read_inline_image(self, stream: StreamType) -> Dict[str, Any]:
data = extract_inline_default(stream)

ei = stream.read(2)
assert ei == b"EI"
if ei != b"EI":
stream.seek(savpos, 0)
data = extract_inline_default(stream)
return {"settings": settings, "data": data}

# This overrides the parent method:
Expand Down
4 changes: 1 addition & 3 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,7 @@ def test_extra_test_iss1541():
stream = BytesIO()
cs.write_to_stream(stream)
stream.seek(0)
with pytest.raises(PdfReadError) as exc:
ContentStream(read_object(stream, None, None), None, None).operations
assert exc.value.args[0] == "Unexpected end of stream"
ContentStream(read_object(stream, None, None), None, None).operations

b = BytesIO(data.getbuffer())
reader = PdfReader(
Expand Down

0 comments on commit 44b41a7

Please sign in to comment.