mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-06-11 09:29:21 +00:00
Ensure that boxes aren't bigger than their containers
Together with the entry_count checks, this eliminates several OOMs when reading incorrect mp4 files.
This commit is contained in:
parent
d59c8e304b
commit
e78dbf8f93
|
@ -103,6 +103,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for Avc1Box {
|
|||
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"avc1 box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
if name == BoxType::AvcCBox {
|
||||
let avcc = AvcCBox::read_box(reader, s)?;
|
||||
|
||||
|
|
|
@ -49,6 +49,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for DinfBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"dinf box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::DrefBox => {
|
||||
|
@ -156,6 +161,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for DrefBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"dinf box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::UrlBox => {
|
||||
|
|
|
@ -54,6 +54,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for EdtsBox {
|
|||
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"edts box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
if let BoxType::ElstBox = name {
|
||||
let elst = ElstBox::read_box(reader, s)?;
|
||||
|
|
|
@ -103,6 +103,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for Hev1Box {
|
|||
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"hev1 box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
if name == BoxType::HvcCBox {
|
||||
let hvcc = HvcCBox::read_box(reader, s)?;
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for IlstBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"ilst box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::NameBox => {
|
||||
|
@ -129,6 +134,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for IlstItemBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"ilst item box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::DataBox => {
|
||||
|
|
|
@ -54,6 +54,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for MdiaBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"mdia box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::MdhdBox => {
|
||||
|
|
|
@ -69,6 +69,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for MinfBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"minf box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::VmhdBox => {
|
||||
|
|
|
@ -58,6 +58,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for MoofBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"moof box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::MfhdBox => {
|
||||
|
|
|
@ -77,6 +77,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for MoovBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"moov box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::MvhdBox => {
|
||||
|
|
|
@ -94,6 +94,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for Mp4aBox {
|
|||
if current < start + size {
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"mp4a box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
if name == BoxType::EsdsBox {
|
||||
esds = Some(EsdsBox::read_box(reader, s)?);
|
||||
|
|
|
@ -52,6 +52,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for MvexBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"mvex box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::MehdBox => {
|
||||
|
|
|
@ -92,6 +92,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for StblBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"stbl box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::StsdBox => {
|
||||
|
|
|
@ -85,6 +85,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for StsdBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"stsd box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::Avc1Box => {
|
||||
|
|
|
@ -59,6 +59,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for TrafBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"traf box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::TfhdBox => {
|
||||
|
|
|
@ -68,6 +68,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for TrakBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"trak box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::TkhdBox => {
|
||||
|
|
|
@ -55,6 +55,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for UdtaBox {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"udta box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
match name {
|
||||
BoxType::MetaBox => {
|
||||
|
|
|
@ -121,6 +121,11 @@ impl<R: Read + Seek> ReadBox<&mut R> for Vp09Box {
|
|||
|
||||
let vpcc = {
|
||||
let header = BoxHeader::read(reader)?;
|
||||
if header.size > size {
|
||||
return Err(Error::InvalidData(
|
||||
"vp09 box contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
VpccBox::read_box(reader, header.size)?
|
||||
};
|
||||
|
||||
|
|
|
@ -31,6 +31,11 @@ impl<R: Read + Seek> Mp4Reader<R> {
|
|||
// Get box header.
|
||||
let header = BoxHeader::read(&mut reader)?;
|
||||
let BoxHeader { name, size: s } = header;
|
||||
if s > size {
|
||||
return Err(Error::InvalidData(
|
||||
"file contains a box with a larger size than it",
|
||||
));
|
||||
}
|
||||
|
||||
// Break if size zero BoxHeader, which can result in dead-loop.
|
||||
if s == 0 {
|
||||
|
|
Loading…
Reference in a new issue