diff --git a/pypdf/filters.py b/pypdf/filters.py index ea6e0ada7..95c08afb1 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -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) diff --git a/tests/test_filters.py b/tests/test_filters.py index 0e86572cb..0edcd85b5 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -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">"