Skip to content

Commit a1c3366

Browse files
ROB: Handle DecodeParms being a NullObject (#3285)
1 parent d673355 commit a1c3366

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pypdf/filters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ def _apply_alpha(
787787
decode_parms = decode_parms[0]
788788
else:
789789
decode_parms = {}
790+
if not isinstance(decode_parms, dict):
791+
decode_parms = {}
790792

791793
extension = None
792794
if lfilters in (FT.FLATE_DECODE, FT.RUN_LENGTH_DECODE):

tests/test_filters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,14 @@ def test_ccitt_fax_decode__black_is_1():
655655
actual_pixels = list(actual_image.getdata())
656656
assert expected_pixels == actual_pixels
657657

658+
# AttributeError: 'NullObject' object has no attribute 'get'
659+
data_modified = get_data_from_url(url, name=name).replace(
660+
b"/DecodeParms [ << /K -1 /BlackIs1 true /Columns 16 /Rows 16 >> ]",
661+
b"/DecodeParms [ null ]"
662+
)
663+
reader = PdfReader(BytesIO(data_modified))
664+
_ = reader.pages[0].images[0].image
665+
658666

659667
@pytest.mark.enable_socket
660668
def test_flate_decode__image_is_none_due_to_size_limit(caplog):

0 commit comments

Comments
 (0)