Skip to content

Commit 26af474

Browse files
committed
Add test to check that invalid userdata isn't fatal to parsing.
1 parent 9fb77e6 commit 26af474

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

mp4parse/tests/invalid_userdata.mp4

132 KB
Binary file not shown.

mp4parse/tests/public.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ static VIDEO_EME_CENC_MP4: &str = "tests/bipbop_480wp_1001kbps-cenc-video-key1-i
2828
static AUDIO_EME_CBCS_MP4: &str = "tests/bipbop_cbcs_audio_init.mp4";
2929
static VIDEO_EME_CBCS_MP4: &str = "tests/bipbop_cbcs_video_init.mp4";
3030
static VIDEO_AV1_MP4: &str = "tests/tiny_av1.mp4";
31+
// This file contains invalid userdata in its copyright userdata. See
32+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1687357 for more information.
33+
static VIDEO_INVALID_USERDATA: &str = "tests/invalid_userdata.mp4";
3134
static IMAGE_AVIF: &str = "av1-avif/testFiles/Microsoft/Monochrome.avif";
3235
static IMAGE_AVIF_EXTENTS: &str = "tests/kodim-extents.avif";
3336
static IMAGE_AVIF_ALPHA: &str = "tests/bug-1661347.avif";
@@ -291,6 +294,46 @@ fn public_metadata_gnre() {
291294
assert_eq!(u32::from_le_bytes(bytes), 0x00ff_d8ff);
292295
}
293296

297+
#[test]
298+
fn public_invalid_metadata() {
299+
// Test that reading userdata containing invalid metadata is not fatal to parsing and that
300+
// expected values are still found.
301+
let mut fd = File::open(VIDEO_INVALID_USERDATA).expect("Unknown file");
302+
let mut buf = Vec::new();
303+
fd.read_to_end(&mut buf).expect("File error");
304+
305+
let mut c = Cursor::new(&buf);
306+
let context = mp4::read_mp4(&mut c).expect("read_mp4 failed");
307+
// Should have userdata.
308+
assert!(context.userdata.is_some());
309+
// But it should contain an error.
310+
assert!(context.userdata.unwrap().is_err());
311+
// Smoke test that other data has been parsed. Don't check everything, just make sure some
312+
// values are as expected.
313+
assert_eq!(context.tracks.len(), 2);
314+
for track in context.tracks {
315+
match track.track_type {
316+
mp4::TrackType::Video => {
317+
// Check some of the values in the video tkhd.
318+
let tkhd = track.tkhd.unwrap();
319+
assert_eq!(tkhd.disabled, false);
320+
assert_eq!(tkhd.duration, 231232);
321+
assert_eq!(tkhd.width, 83_886_080);
322+
assert_eq!(tkhd.height, 47_185_920);
323+
}
324+
mp4::TrackType::Audio => {
325+
// Check some of the values in the audio tkhd.
326+
let tkhd = track.tkhd.unwrap();
327+
assert_eq!(tkhd.disabled, false);
328+
assert_eq!(tkhd.duration, 231338);
329+
assert_eq!(tkhd.width, 0);
330+
assert_eq!(tkhd.height, 0);
331+
}
332+
_ => panic!("File should not contain other tracks.")
333+
}
334+
}
335+
}
336+
294337
#[test]
295338
fn public_audio_tenc() {
296339
let kid = vec![

0 commit comments

Comments
 (0)