Skip to content

Try to skip extended header in MetaBox. #111

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 2 commits into from
Jul 29, 2023
Merged
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
16 changes: 13 additions & 3 deletions src/mp4box/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,19 @@ impl<R: Read + Seek> ReadBox<&mut R> for MetaBox {
fn read_box(reader: &mut R, size: u64) -> Result<Self> {
let start = box_start(reader)?;

let (version, _) = read_box_header_ext(reader)?;
if version != 0 {
return Err(Error::UnsupportedBoxVersion(BoxType::UdtaBox, version));
let extended_header = reader.read_u32::<BigEndian>()?;
if extended_header != 0 {
// ISO mp4 requires this header (version & flags) to be 0. Some
// files skip the extended header and directly start the hdlr box.
let possible_hdlr = BoxType::from(reader.read_u32::<BigEndian>()?);
if possible_hdlr == BoxType::HdlrBox {
// This file skipped the extended header! Go back to start.
reader.seek(SeekFrom::Current(-8))?;
} else {
// Looks like we actually have a bad version number or flags.
let v = (extended_header >> 24) as u8;
return Err(Error::UnsupportedBoxVersion(BoxType::MetaBox, v));
}
}

let mut current = reader.stream_position()?;
Expand Down