|
6 | 6 | from io import BytesIO |
7 | 7 | from itertools import product as cartesian_product |
8 | 8 | from pathlib import Path |
| 9 | +from typing import cast |
9 | 10 | from unittest import mock |
10 | 11 |
|
11 | 12 | import pytest |
|
30 | 31 | NameObject, |
31 | 32 | NullObject, |
32 | 33 | NumberObject, |
| 34 | + StreamObject, |
33 | 35 | ) |
34 | 36 |
|
35 | 37 | from . import PILContext, get_data_from_url |
@@ -790,3 +792,27 @@ def test_jbig2decode__edge_cases(caplog): |
790 | 792 | "jbig2dec FATAL ERROR page has no image, cannot be completed", |
791 | 793 | "jbig2dec WARNING unable to complete page" |
792 | 794 | ] |
| 795 | + |
| 796 | + |
| 797 | +@pytest.mark.timeout(timeout=30, method="thread") |
| 798 | +@pytest.mark.enable_socket |
| 799 | +def test_flate_decode_stream_with_faulty_tail_bytes(): |
| 800 | + """ |
| 801 | + Test for #3332 |
| 802 | +
|
| 803 | + The test ensures two things: |
| 804 | + 1. stream can be decoded at all |
| 805 | + 2. decoding doesn't falls through to last fallback in try-except blocks |
| 806 | + that is too slow and takes ages for this stream |
| 807 | + """ |
| 808 | + data = get_data_from_url( |
| 809 | + url="https://github.com/user-attachments/files/20901522/faulty_stream_tail_example.1.pdf", |
| 810 | + name="faulty_stream_tail_example.1.pdf" |
| 811 | + ) |
| 812 | + expected = get_data_from_url( |
| 813 | + url="https://github.com/user-attachments/files/20941717/decoded.dat.txt", |
| 814 | + name="faulty_stream_tail_example.1.decoded.dat" |
| 815 | + ) |
| 816 | + reader = PdfReader(BytesIO(data)) |
| 817 | + obj = reader.get_object(IndirectObject(182, 0, reader)) |
| 818 | + assert cast(StreamObject, obj).get_data() == expected |
0 commit comments