Skip to content

Commit 5de0b0a

Browse files
committed
Reject mp4 files that have a track timescale of 0.
1 parent 8e53cd9 commit 5de0b0a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

mp4parse_capi/src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,9 @@ pub unsafe extern "C" fn mp4parse_get_track_info(
650650
info.duration = 0
651651
}
652652
}
653-
};
653+
} else {
654+
return Mp4parseStatus::Invalid;
655+
}
654656

655657
info.track_id = match track.track_id {
656658
Some(track_id) => track_id,
@@ -1838,3 +1840,24 @@ fn minimal_mp4_get_track_info_invalid_track_number() {
18381840
mp4parse_free(parser);
18391841
}
18401842
}
1843+
1844+
#[test]
1845+
fn parse_no_timescale() {
1846+
let mut file = std::fs::File::open("tests/no_timescale.mp4").expect("Unknown file");
1847+
let io = Mp4parseIo {
1848+
read: Some(valid_read),
1849+
userdata: &mut file as *mut _ as *mut std::os::raw::c_void,
1850+
};
1851+
1852+
unsafe {
1853+
let mut parser = std::ptr::null_mut();
1854+
let mut rv = mp4parse_new(&io, &mut parser);
1855+
assert_eq!(rv, Mp4parseStatus::Ok);
1856+
assert!(!parser.is_null());
1857+
1858+
// The file has a video track, but the track has a timescale of 0, so.
1859+
let mut track_info = Mp4parseTrackInfo::default();
1860+
rv = mp4parse_get_track_info(parser, 0, &mut track_info);
1861+
assert_eq!(rv, Mp4parseStatus::Invalid);
1862+
};
1863+
}

mp4parse_capi/tests/no_timescale.mp4

78.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)