Skip to content
Open
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
37 changes: 26 additions & 11 deletions mp4parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4485,7 +4485,7 @@ fn read_ftyp<T: Read>(src: &mut BMFFBox<T>) -> Result<FileTypeBox> {
let major = be_u32(src)?;
let minor = be_u32(src)?;
let bytes_left = src.bytes_left();
if bytes_left % 4 != 0 {
if !bytes_left.is_multiple_of(4) {
return Status::FtypBadSize.into();
}
// Is a brand_count of zero valid?
Expand Down Expand Up @@ -5515,7 +5515,10 @@ fn read_hdlr<T: Read>(src: &mut BMFFBox<T>, strictness: ParseStrictness) -> Resu
}

/// Parse an video description inside an stsd box.
fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry> {
fn read_video_sample_entry<T: Read>(
src: &mut BMFFBox<T>,
strictness: ParseStrictness,
) -> Result<SampleEntry> {
let name = src.get_header().name;
let codec_type = match name {
BoxType::AVCSampleEntry | BoxType::AVC3SampleEntry => CodecType::H264,
Expand Down Expand Up @@ -5670,7 +5673,12 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
skip_box_content(&mut b)?;
}
}
check_parser_state!(b.content);
if strictness == ParseStrictness::Strict {
check_parser_state!(b.content);
} else {
// Padding may be present in some content.
skip_box_remain(&mut b)?;
}
}

Ok(
Expand Down Expand Up @@ -5818,11 +5826,18 @@ fn read_audio_sample_entry<T: Read>(
codec_type = CodecType::ALAC;
codec_specific = Some(AudioCodecSpecific::ALACSpecificBox(alac));
}
BoxType::QTWaveAtom => {
let qt_esds = read_qt_wave_atom(&mut b, strictness)?;
codec_type = qt_esds.audio_codec;
codec_specific = Some(AudioCodecSpecific::ES_Descriptor(qt_esds));
}
BoxType::QTWaveAtom => match read_qt_wave_atom(&mut b, strictness) {
Ok(qt_esds) => {
codec_type = qt_esds.audio_codec;
codec_specific = Some(AudioCodecSpecific::ES_Descriptor(qt_esds));
}
Err(e) => {
warn!("Failed to parse wave atom: {e:?}");
if strictness == ParseStrictness::Strict {
return Err(e);
}
}
},
BoxType::ProtectionSchemeInfoBox => {
if name != BoxType::ProtectedAudioSampleEntry {
return Status::StsdBadAudioSampleEntry.into();
Expand Down Expand Up @@ -5890,9 +5905,9 @@ fn read_stsd<T: Read>(
while descriptions.len() < description_count {
if let Some(mut b) = iter.next_box()? {
let description = match track.track_type {
TrackType::Video => read_video_sample_entry(&mut b),
TrackType::Picture => read_video_sample_entry(&mut b),
TrackType::AuxiliaryVideo => read_video_sample_entry(&mut b),
TrackType::Video => read_video_sample_entry(&mut b, strictness),
TrackType::Picture => read_video_sample_entry(&mut b, strictness),
TrackType::AuxiliaryVideo => read_video_sample_entry(&mut b, strictness),
TrackType::Audio => read_audio_sample_entry(&mut b, strictness),
TrackType::Metadata => Err(Error::Unsupported("metadata track")),
TrackType::Unknown => Err(Error::Unsupported("unknown track type")),
Expand Down
5 changes: 3 additions & 2 deletions mp4parse/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ fn read_stsd_mp4v() {
let mut iter = super::BoxIter::new(&mut stream);
let mut stream = iter.next_box().unwrap().unwrap();

let sample_entry = super::read_video_sample_entry(&mut stream).unwrap();
let sample_entry =
super::read_video_sample_entry(&mut stream, ParseStrictness::Normal).unwrap();

match sample_entry {
super::SampleEntry::Video(v) => {
Expand Down Expand Up @@ -1247,7 +1248,7 @@ fn unknown_video_sample_entry() {
});
let mut iter = super::BoxIter::new(&mut stream);
let mut stream = iter.next_box().unwrap().unwrap();
match super::read_video_sample_entry(&mut stream) {
match super::read_video_sample_entry(&mut stream, ParseStrictness::Normal) {
Ok(super::SampleEntry::Unknown) => (),
_ => panic!("expected a different error result"),
}
Expand Down