@@ -253,6 +253,24 @@ def test_read_video_timestamps_corrupted_file(self):
253
253
self .assertEqual (video_pts , [])
254
254
self .assertIs (video_fps , None )
255
255
256
+ def test_read_video_partially_corrupted_file (self ):
257
+ with temp_video (5 , 4 , 4 , 5 , lossless = True ) as (f_name , data ):
258
+ with open (f_name , 'r+b' ) as f :
259
+ size = os .path .getsize (f_name )
260
+ bytes_to_overwrite = size // 10
261
+ # seek to the middle of the file
262
+ f .seek (5 * bytes_to_overwrite )
263
+ # corrupt 10% of the file from the middle
264
+ f .write (b'\xff ' * bytes_to_overwrite )
265
+ # this exercises the container.decode assertion check
266
+ video , audio , info = io .read_video (f .name , pts_unit = 'sec' )
267
+ # check that size is not equal to 5, but 3
268
+ self .assertEqual (len (video ), 3 )
269
+ # but the valid decoded content is still correct
270
+ self .assertTrue (video [:3 ].equal (data [:3 ]))
271
+ # and the last few frames are wrong
272
+ self .assertFalse (video .equal (data ))
273
+
256
274
# TODO add tests for audio
257
275
258
276
0 commit comments