@@ -119,36 +119,36 @@ def test_large_count(tmp_path: Path) -> None:
119119 _roundtrip (tmp_path , im )
120120
121121
122- def _test_buffer_overflow (tmp_path : Path , im : Image .Image , size : int = 1024 ) -> None :
123- _last = ImageFile .MAXBLOCK
124- ImageFile .MAXBLOCK = size
125- try :
126- _roundtrip (tmp_path , im )
127- finally :
128- ImageFile .MAXBLOCK = _last
122+ def _test_buffer_overflow (
123+ tmp_path : Path , im : Image .Image , monkeypatch : pytest .MonkeyPatch
124+ ) -> None :
125+ monkeypatch .setattr (ImageFile , "MAXBLOCK" , 1024 )
126+ _roundtrip (tmp_path , im )
129127
130128
131- def test_break_in_count_overflow (tmp_path : Path ) -> None :
129+ def test_break_in_count_overflow (
130+ tmp_path : Path , monkeypatch : pytest .MonkeyPatch
131+ ) -> None :
132132 im = Image .new ("L" , (256 , 5 ))
133133 px = im .load ()
134134 assert px is not None
135135 for y in range (4 ):
136136 for x in range (256 ):
137137 px [x , y ] = x % 128
138- _test_buffer_overflow (tmp_path , im )
138+ _test_buffer_overflow (tmp_path , im , monkeypatch )
139139
140140
141- def test_break_one_in_loop (tmp_path : Path ) -> None :
141+ def test_break_one_in_loop (tmp_path : Path , monkeypatch : pytest . MonkeyPatch ) -> None :
142142 im = Image .new ("L" , (256 , 5 ))
143143 px = im .load ()
144144 assert px is not None
145145 for y in range (5 ):
146146 for x in range (256 ):
147147 px [x , y ] = x % 128
148- _test_buffer_overflow (tmp_path , im )
148+ _test_buffer_overflow (tmp_path , im , monkeypatch )
149149
150150
151- def test_break_many_in_loop (tmp_path : Path ) -> None :
151+ def test_break_many_in_loop (tmp_path : Path , monkeypatch : pytest . MonkeyPatch ) -> None :
152152 im = Image .new ("L" , (256 , 5 ))
153153 px = im .load ()
154154 assert px is not None
@@ -157,21 +157,21 @@ def test_break_many_in_loop(tmp_path: Path) -> None:
157157 px [x , y ] = x % 128
158158 for x in range (8 ):
159159 px [x , 4 ] = 16
160- _test_buffer_overflow (tmp_path , im )
160+ _test_buffer_overflow (tmp_path , im , monkeypatch )
161161
162162
163- def test_break_one_at_end (tmp_path : Path ) -> None :
163+ def test_break_one_at_end (tmp_path : Path , monkeypatch : pytest . MonkeyPatch ) -> None :
164164 im = Image .new ("L" , (256 , 5 ))
165165 px = im .load ()
166166 assert px is not None
167167 for y in range (5 ):
168168 for x in range (256 ):
169169 px [x , y ] = x % 128
170170 px [0 , 3 ] = 128 + 64
171- _test_buffer_overflow (tmp_path , im )
171+ _test_buffer_overflow (tmp_path , im , monkeypatch )
172172
173173
174- def test_break_many_at_end (tmp_path : Path ) -> None :
174+ def test_break_many_at_end (tmp_path : Path , monkeypatch : pytest . MonkeyPatch ) -> None :
175175 im = Image .new ("L" , (256 , 5 ))
176176 px = im .load ()
177177 assert px is not None
@@ -181,10 +181,10 @@ def test_break_many_at_end(tmp_path: Path) -> None:
181181 for x in range (4 ):
182182 px [x * 2 , 3 ] = 128 + 64
183183 px [x + 256 - 4 , 3 ] = 0
184- _test_buffer_overflow (tmp_path , im )
184+ _test_buffer_overflow (tmp_path , im , monkeypatch )
185185
186186
187- def test_break_padding (tmp_path : Path ) -> None :
187+ def test_break_padding (tmp_path : Path , monkeypatch : pytest . MonkeyPatch ) -> None :
188188 im = Image .new ("L" , (257 , 5 ))
189189 px = im .load ()
190190 assert px is not None
@@ -193,4 +193,4 @@ def test_break_padding(tmp_path: Path) -> None:
193193 px [x , y ] = x % 128
194194 for x in range (5 ):
195195 px [x , 3 ] = 0
196- _test_buffer_overflow (tmp_path , im )
196+ _test_buffer_overflow (tmp_path , im , monkeypatch )
0 commit comments