Skip to content

Return an error when a track has a timescale of 0. #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion mp4parse_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ pub unsafe extern "C" fn mp4parse_get_track_info(
info.duration = 0
}
}
};
} else {
return Mp4parseStatus::Invalid;
}

info.track_id = match track.track_id {
Some(track_id) => track_id,
Expand Down Expand Up @@ -1838,3 +1840,24 @@ fn minimal_mp4_get_track_info_invalid_track_number() {
mp4parse_free(parser);
}
}

#[test]
fn parse_no_timescale() {
let mut file = std::fs::File::open("tests/no_timescale.mp4").expect("Unknown file");
let io = Mp4parseIo {
read: Some(valid_read),
userdata: &mut file as *mut _ as *mut std::os::raw::c_void,
};

unsafe {
let mut parser = std::ptr::null_mut();
let mut rv = mp4parse_new(&io, &mut parser);
assert_eq!(rv, Mp4parseStatus::Ok);
assert!(!parser.is_null());

// The file has a video track, but the track has a timescale of 0, so.
let mut track_info = Mp4parseTrackInfo::default();
rv = mp4parse_get_track_info(parser, 0, &mut track_info);
assert_eq!(rv, Mp4parseStatus::Invalid);
};
}
Binary file added mp4parse_capi/tests/no_timescale.mp4
Binary file not shown.