diff --git a/src/mp4box/dinf.rs b/src/mp4box/dinf.rs index e365e4ae..b6ab4845 100644 --- a/src/mp4box/dinf.rs +++ b/src/mp4box/dinf.rs @@ -232,7 +232,7 @@ impl UrlBox { let mut size = HEADER_SIZE + HEADER_EXT_SIZE; if !self.location.is_empty() { - size += self.location.bytes().len() as u64 + 1; + size += self.location.len() as u64 + 1; } size diff --git a/src/mp4box/ftyp.rs b/src/mp4box/ftyp.rs index 789cd4ef..fa8c1fc2 100644 --- a/src/mp4box/ftyp.rs +++ b/src/mp4box/ftyp.rs @@ -53,6 +53,7 @@ impl ReadBox<&mut R> for FtypBox { fn read_box(reader: &mut R, size: u64) -> Result { let start = box_start(reader)?; + #[allow(clippy::manual_is_multiple_of)] if size < 16 || size % 4 != 0 { return Err(Error::InvalidData("ftyp size too small or not aligned")); } diff --git a/src/mp4box/ilst.rs b/src/mp4box/ilst.rs index d0292a31..1a4e4332 100644 --- a/src/mp4box/ilst.rs +++ b/src/mp4box/ilst.rs @@ -166,7 +166,7 @@ impl ReadBox<&mut R> for IlstItemBox { } impl<'a> Metadata<'a> for IlstBox { - fn title(&self) -> Option> { + fn title(&'_ self) -> Option> { self.items.get(&MetadataKey::Title).map(item_to_str) } @@ -178,7 +178,7 @@ impl<'a> Metadata<'a> for IlstBox { self.items.get(&MetadataKey::Poster).map(item_to_bytes) } - fn summary(&self) -> Option> { + fn summary(&'_ self) -> Option> { self.items.get(&MetadataKey::Summary).map(item_to_str) } } @@ -187,7 +187,7 @@ fn item_to_bytes(item: &IlstItemBox) -> &[u8] { &item.data.data } -fn item_to_str(item: &IlstItemBox) -> Cow { +fn item_to_str(item: &'_ IlstItemBox) -> Cow<'_, str> { String::from_utf8_lossy(&item.data.data) } diff --git a/src/mp4box/mod.rs b/src/mp4box/mod.rs index 4bbdd410..da3a6c8d 100644 --- a/src/mp4box/mod.rs +++ b/src/mp4box/mod.rs @@ -348,6 +348,10 @@ pub fn skip_bytes_to(seeker: &mut S, pos: u64) -> Result<()> { pub fn skip_box(seeker: &mut S, size: u64) -> Result<()> { let start = box_start(seeker)?; + + // if we're jumping to the same place, it's probably a bug in the caller + assert!(size > 0); + skip_bytes_to(seeker, start + size)?; Ok(()) } diff --git a/src/mp4box/mp4a.rs b/src/mp4box/mp4a.rs index a80c6c46..d7f6f25b 100644 --- a/src/mp4box/mp4a.rs +++ b/src/mp4box/mp4a.rs @@ -285,7 +285,7 @@ fn size_of_length(size: u32) -> u32 { fn write_desc(writer: &mut W, tag: u8, size: u32) -> Result { writer.write_u8(tag)?; - if size as u64 > std::u32::MAX as u64 { + if size as u64 > u32::MAX as u64 { return Err(Error::InvalidData("invalid descriptor length range")); } diff --git a/src/mp4box/stbl.rs b/src/mp4box/stbl.rs index ef8433b4..cd6e99d5 100644 --- a/src/mp4box/stbl.rs +++ b/src/mp4box/stbl.rs @@ -98,6 +98,11 @@ impl ReadBox<&mut R> for StblBox { )); } + // Break if size zero BoxHeader, which can result in dead-loop. + if s == 0 { + break; + } + match name { BoxType::StsdBox => { stsd = Some(StsdBox::read_box(reader, s)?); diff --git a/src/track.rs b/src/track.rs index 7eada834..03e64356 100644 --- a/src/track.rs +++ b/src/track.rs @@ -261,7 +261,7 @@ impl Mp4Track { pub fn sequence_parameter_set(&self) -> Result<&[u8]> { if let Some(ref avc1) = self.trak.mdia.minf.stbl.stsd.avc1 { - match avc1.avcc.sequence_parameter_sets.get(0) { + match avc1.avcc.sequence_parameter_sets.first() { Some(nal) => Ok(nal.bytes.as_ref()), None => Err(Error::EntryInStblNotFound( self.track_id(), @@ -276,7 +276,7 @@ impl Mp4Track { pub fn picture_parameter_set(&self) -> Result<&[u8]> { if let Some(ref avc1) = self.trak.mdia.minf.stbl.stsd.avc1 { - match avc1.avcc.picture_parameter_sets.get(0) { + match avc1.avcc.picture_parameter_sets.first() { Some(nal) => Ok(nal.bytes.as_ref()), None => Err(Error::EntryInStblNotFound( self.track_id(), @@ -580,6 +580,8 @@ impl Mp4Track { fn is_sync_sample(&self, sample_id: u32) -> bool { if !self.trafs.is_empty() { let sample_sizes_count = self.sample_count() / self.trafs.len() as u32; + + #[allow(clippy::manual_is_multiple_of)] return sample_id == 1 || sample_id % sample_sizes_count == 0; } diff --git a/src/types.rs b/src/types.rs index 540f7fb0..5d42ed11 100644 --- a/src/types.rs +++ b/src/types.rs @@ -695,17 +695,17 @@ pub enum MetadataKey { pub trait Metadata<'a> { /// The video's title - fn title(&self) -> Option>; + fn title(&'_ self) -> Option>; /// The video's release year fn year(&self) -> Option; /// The video's poster (cover art) fn poster(&self) -> Option<&[u8]>; /// The video's summary - fn summary(&self) -> Option>; + fn summary(&self) -> Option>; } impl<'a, T: Metadata<'a>> Metadata<'a> for &'a T { - fn title(&self) -> Option> { + fn title(&'_ self) -> Option> { (**self).title() } @@ -717,13 +717,13 @@ impl<'a, T: Metadata<'a>> Metadata<'a> for &'a T { (**self).poster() } - fn summary(&self) -> Option> { + fn summary(&self) -> Option> { (**self).summary() } } impl<'a, T: Metadata<'a>> Metadata<'a> for Option { - fn title(&self) -> Option> { + fn title(&'_ self) -> Option> { self.as_ref().and_then(|t| t.title()) } @@ -735,7 +735,7 @@ impl<'a, T: Metadata<'a>> Metadata<'a> for Option { self.as_ref().and_then(|t| t.poster()) } - fn summary(&self) -> Option> { + fn summary(&'_ self) -> Option> { self.as_ref().and_then(|t| t.summary()) } } diff --git a/src/writer.rs b/src/writer.rs index a83a888c..eac3a247 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -117,7 +117,7 @@ impl Mp4Writer { fn update_mdat_size(&mut self) -> Result<()> { let mdat_end = self.writer.stream_position()?; let mdat_size = mdat_end - self.mdat_pos; - if mdat_size > std::u32::MAX as u64 { + if mdat_size > u32::MAX as u64 { self.writer.seek(SeekFrom::Start(self.mdat_pos))?; self.writer.write_u32::(1)?; self.writer.seek(SeekFrom::Start(self.mdat_pos + 8))?;