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
2 changes: 1 addition & 1 deletion src/mp4box/dinf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/mp4box/ftyp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl<R: Read + Seek> ReadBox<&mut R> for FtypBox {
fn read_box(reader: &mut R, size: u64) -> Result<Self> {
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"));
}
Expand Down
6 changes: 3 additions & 3 deletions src/mp4box/ilst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<R: Read + Seek> ReadBox<&mut R> for IlstItemBox {
}

impl<'a> Metadata<'a> for IlstBox {
fn title(&self) -> Option<Cow<str>> {
fn title(&'_ self) -> Option<Cow<'_, str>> {
self.items.get(&MetadataKey::Title).map(item_to_str)
}

Expand All @@ -178,7 +178,7 @@ impl<'a> Metadata<'a> for IlstBox {
self.items.get(&MetadataKey::Poster).map(item_to_bytes)
}

fn summary(&self) -> Option<Cow<str>> {
fn summary(&'_ self) -> Option<Cow<'_, str>> {
self.items.get(&MetadataKey::Summary).map(item_to_str)
}
}
Expand All @@ -187,7 +187,7 @@ fn item_to_bytes(item: &IlstItemBox) -> &[u8] {
&item.data.data
}

fn item_to_str(item: &IlstItemBox) -> Cow<str> {
fn item_to_str(item: &'_ IlstItemBox) -> Cow<'_, str> {
String::from_utf8_lossy(&item.data.data)
}

Expand Down
4 changes: 4 additions & 0 deletions src/mp4box/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ pub fn skip_bytes_to<S: Seek>(seeker: &mut S, pos: u64) -> Result<()> {

pub fn skip_box<S: Seek>(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(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/mp4box/mp4a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ fn size_of_length(size: u32) -> u32 {
fn write_desc<W: Write>(writer: &mut W, tag: u8, size: u32) -> Result<u64> {
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"));
}

Expand Down
5 changes: 5 additions & 0 deletions src/mp4box/stbl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ impl<R: Read + Seek> 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)?);
Expand Down
6 changes: 4 additions & 2 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,17 +695,17 @@ pub enum MetadataKey {

pub trait Metadata<'a> {
/// The video's title
fn title(&self) -> Option<Cow<str>>;
fn title(&'_ self) -> Option<Cow<'_, str>>;
/// The video's release year
fn year(&self) -> Option<u32>;
/// The video's poster (cover art)
fn poster(&self) -> Option<&[u8]>;
/// The video's summary
fn summary(&self) -> Option<Cow<str>>;
fn summary(&self) -> Option<Cow<'_, str>>;
}

impl<'a, T: Metadata<'a>> Metadata<'a> for &'a T {
fn title(&self) -> Option<Cow<str>> {
fn title(&'_ self) -> Option<Cow<'_, str>> {
(**self).title()
}

Expand All @@ -717,13 +717,13 @@ impl<'a, T: Metadata<'a>> Metadata<'a> for &'a T {
(**self).poster()
}

fn summary(&self) -> Option<Cow<str>> {
fn summary(&self) -> Option<Cow<'_, str>> {
(**self).summary()
}
}

impl<'a, T: Metadata<'a>> Metadata<'a> for Option<T> {
fn title(&self) -> Option<Cow<str>> {
fn title(&'_ self) -> Option<Cow<'_, str>> {
self.as_ref().and_then(|t| t.title())
}

Expand All @@ -735,7 +735,7 @@ impl<'a, T: Metadata<'a>> Metadata<'a> for Option<T> {
self.as_ref().and_then(|t| t.poster())
}

fn summary(&self) -> Option<Cow<str>> {
fn summary(&'_ self) -> Option<Cow<'_, str>> {
self.as_ref().and_then(|t| t.summary())
}
}
2 changes: 1 addition & 1 deletion src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<W: Write + Seek> Mp4Writer<W> {
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::<BigEndian>(1)?;
self.writer.seek(SeekFrom::Start(self.mdat_pos + 8))?;
Expand Down
Loading