@@ -29,7 +29,7 @@ def test_get_imagemode_recursion_depth():
29
29
reader .pages [0 ].images [0 ]
30
30
31
31
32
- def test_handle_flate__image_mode_1 ():
32
+ def test_handle_flate__image_mode_1 (caplog ):
33
33
data = b"\x00 \xe0 \x00 "
34
34
lookup = DecodedStreamObject ()
35
35
expected_data = [
@@ -57,6 +57,7 @@ def test_handle_flate__image_mode_1():
57
57
obj_as_text = "dummy" ,
58
58
)
59
59
assert expected_data == list (result [0 ].getdata ())
60
+ assert not caplog .text
60
61
61
62
# Trailing whitespace.
62
63
lookup .set_data (b"\x42 \x42 \x42 \x00 \x13 \x37 \x0a " )
@@ -71,48 +72,51 @@ def test_handle_flate__image_mode_1():
71
72
obj_as_text = "dummy" ,
72
73
)
73
74
assert expected_data == list (result [0 ].getdata ())
75
+ assert not caplog .text
74
76
75
77
# Trailing non-whitespace character.
76
78
lookup .set_data (b"\x42 \x42 \x42 \x00 \x13 \x37 \x12 " )
77
- with pytest .raises (
78
- PdfReadError , match = r"^Too many lookup values: Expected 6, got 7\.$"
79
- ):
80
- _handle_flate (
81
- size = (3 , 3 ),
82
- data = data ,
83
- mode = "1" ,
84
- color_space = ArrayObject (
85
- [
86
- NameObject ("/Indexed" ),
87
- NameObject ("/DeviceRGB" ),
88
- NumberObject (1 ),
89
- lookup ,
90
- ]
91
- ),
92
- colors = 2 ,
93
- obj_as_text = "dummy" ,
94
- )
79
+ result = _handle_flate (
80
+ size = (3 , 3 ),
81
+ data = data ,
82
+ mode = "1" ,
83
+ color_space = ArrayObject (
84
+ [
85
+ NameObject ("/Indexed" ),
86
+ NameObject ("/DeviceRGB" ),
87
+ NumberObject (1 ),
88
+ lookup ,
89
+ ]
90
+ ),
91
+ colors = 2 ,
92
+ obj_as_text = "dummy" ,
93
+ )
94
+ assert expected_data == list (result [0 ].getdata ())
95
+ assert "Too many lookup values: Expected 6, got 7." in caplog .text
95
96
96
97
# Not enough lookup data.
98
+ # `\xe0` of the original input (the middle part) does not use `0x37 = 55` for the lookup
99
+ # here, but received a custom padding of `0`.
97
100
lookup .set_data (b"\x42 \x42 \x42 \x00 \x13 " )
98
- with pytest .raises (
99
- PdfReadError , match = r"^Not enough lookup values: Expected 6, got 5\.$"
100
- ):
101
- _handle_flate (
102
- size = (3 , 3 ),
103
- data = data ,
104
- mode = "1" ,
105
- color_space = ArrayObject (
106
- [
107
- NameObject ("/Indexed" ),
108
- NameObject ("/DeviceRGB" ),
109
- NumberObject (1 ),
110
- lookup ,
111
- ]
112
- ),
113
- colors = 2 ,
114
- obj_as_text = "dummy" ,
115
- )
101
+ caplog .clear ()
102
+ expected_short_data = [entry if entry [0 ] == 66 else (0 , 19 , 0 ) for entry in expected_data ]
103
+ result = _handle_flate (
104
+ size = (3 , 3 ),
105
+ data = data ,
106
+ mode = "1" ,
107
+ color_space = ArrayObject (
108
+ [
109
+ NameObject ("/Indexed" ),
110
+ NameObject ("/DeviceRGB" ),
111
+ NumberObject (1 ),
112
+ lookup ,
113
+ ]
114
+ ),
115
+ colors = 2 ,
116
+ obj_as_text = "dummy" ,
117
+ )
118
+ assert expected_short_data == list (result [0 ].getdata ())
119
+ assert "Not enough lookup values: Expected 6, got 5." in caplog .text
116
120
117
121
118
122
def test_extended_image_frombytes_zero_data ():
0 commit comments