|
22 | 22 | CCITTParameters,
|
23 | 23 | FlateDecode,
|
24 | 24 | JBIG2Decode,
|
| 25 | + RunLengthDecode, |
25 | 26 | )
|
26 | 27 | from pypdf.generic import (
|
27 | 28 | ArrayObject,
|
@@ -816,3 +817,38 @@ def test_flate_decode_stream_with_faulty_tail_bytes():
|
816 | 817 | reader = PdfReader(BytesIO(data))
|
817 | 818 | obj = reader.get_object(IndirectObject(182, 0, reader))
|
818 | 819 | assert cast(StreamObject, obj).get_data() == expected
|
| 820 | + |
| 821 | + |
| 822 | +@pytest.mark.enable_socket |
| 823 | +def test_rle_decode_with_faulty_tail_byte_in_multi_encoded_stream(caplog): |
| 824 | + """ |
| 825 | + Test for #3355 |
| 826 | +
|
| 827 | + The test ensures that the inner RLE encoded stream can be decoded, |
| 828 | + because this stream contains an extra faulty newline byte in the |
| 829 | + end that can be ignored during decoding. |
| 830 | + """ |
| 831 | + data = get_data_from_url( |
| 832 | + url="https://github.com/user-attachments/files/21038398/test_data_rle.txt", |
| 833 | + name="multi_decoding_example_with_faulty_tail_byte.pdf" |
| 834 | + ) |
| 835 | + reader = PdfReader(BytesIO(data)) |
| 836 | + obj = reader.get_object(IndirectObject(60, 0, reader)) |
| 837 | + cast(StreamObject, obj).get_data() |
| 838 | + assert "Found trailing newline in stream data, check if output is OK" in caplog.messages |
| 839 | + |
| 840 | + |
| 841 | +@pytest.mark.enable_socket |
| 842 | +def test_rle_decode_exception_with_corrupted_stream(): |
| 843 | + """ |
| 844 | + Additional Test to #3355 |
| 845 | +
|
| 846 | + This test must raise the EOD exception during RLE decoding and ensures |
| 847 | + that we do not fail during code coverage analyses in the git PR pipeline. |
| 848 | + """ |
| 849 | + data = get_data_from_url( |
| 850 | + url="https://github.com/user-attachments/files/21052626/rle_stream_with_error.txt", |
| 851 | + name="rle_stream_with_error.txt" |
| 852 | + ) |
| 853 | + with pytest.raises(PdfStreamError, match="Early EOD in RunLengthDecode"): |
| 854 | + RunLengthDecode.decode(data) |
0 commit comments