Skip to content

Commit f3d2ced

Browse files
fix: Add compatibility for source assets that report mdat box sizes that e… (#1956)
* Add compatibility for source assets that report mdat box sizes that extend beyond the end of the content. * simplification * remove unneeded library
1 parent b6d4ebc commit f3d2ced

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sdk/src/asset_handlers/bmff_io.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,15 +1297,21 @@ pub(crate) fn build_bmff_tree<R: Read + Seek + ?Sized>(
12971297
.map_err(|err| Error::InvalidAsset(format!("Bad BMFF {err}")))?;
12981298

12991299
// Break if size zero BoxHeader
1300-
let s = header.size;
1300+
let mut s = header.size;
13011301
if s == 0 {
13021302
break;
13031303
}
13041304

13051305
if current + s > end {
1306-
return Err(Error::InvalidAsset(
1307-
"Box size extends beyond asset bounds".to_string(),
1308-
));
1306+
if BoxType::MdatBox == header.name {
1307+
// for mdat boxes that extend beyond the end of the file we will just set the size to the remaining bytes in the file since
1308+
// some files have malformed mdat sizes but we can still hash the content by treating it as a truncated box
1309+
s = end - current;
1310+
} else {
1311+
return Err(Error::InvalidAsset(
1312+
"Box size extends beyond asset bounds".to_string(),
1313+
));
1314+
}
13091315
}
13101316

13111317
// Match and parse the supported atom boxes.

0 commit comments

Comments
 (0)