Skip to content
Open
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 @@ -830,9 +830,10 @@ def decode_stream_data(stream: StreamObject) -> bytes:
# If there is no data to decode, we should not try to decode it.
if not data:
return data
for filter_name, params in zip(filters, decode_parms):
for i, filter_name in enumerate(filters):
params = decode_parms[i] if i < len(decode_parms) else DictionaryObject()
if isinstance(params, NullObject):
params = {}
params = DictionaryObject()
if filter_name in (FT.ASCII_HEX_DECODE, FTA.AHx):
_deprecate_inline_image_filters(filter_name=filter_name, old_name=FTA.AHx, new_name=FT.ASCII_HEX_DECODE)
data = ASCIIHexDecode.decode(data)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,28 @@ def test_runlengthdecode__decode_limit():
assert RunLengthDecode.decode(encoded) == b"A" * uncompressed_size


@pytest.mark.parametrize(
"decode_parms",
[
None,
ArrayObject([DictionaryObject(), DictionaryObject()]),
ArrayObject([DictionaryObject()]),
ArrayObject([]),
],
)
def test_decode_stream_data__short_decode_parms_array(decode_parms):
data = b"Hello World!"
stream = StreamObject()
stream._data = zlib.compress(data).hex().encode("ascii") + b">"
stream[NameObject("/Filter")] = ArrayObject(
[NameObject("/ASCIIHexDecode"), NameObject("/FlateDecode")]
)
if decode_parms is not None:
stream[NameObject("/DecodeParms")] = decode_parms

assert decode_stream_data(stream) == data


@pytest.mark.timeout(10)
def test_asciihexdecode__speed():
encoded = (b"41" * 1_200_000) + b">"
Expand Down
Loading