Skip to content

Commit c1c61e7

Browse files
Zaggy1024kinetiknz
authored andcommitted
Unify bad size error checks in read_box_header
1 parent 64ed99d commit c1c61e7

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

mp4parse/src/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,19 +2348,8 @@ fn read_box_header<T: ReadBytesExt>(src: &mut T) -> Result<Option<BoxHeader>> {
23482348
return Err(Error::Unsupported("unknown sized box"));
23492349
}
23502350
}
2351-
1 => {
2352-
let size64 = be_u64(src)?;
2353-
if size64 < BoxHeader::MIN_LARGE_SIZE {
2354-
return Status::BoxBadWideSize.into();
2355-
}
2356-
size64
2357-
}
2358-
_ => {
2359-
if u64::from(size32) < BoxHeader::MIN_SIZE {
2360-
return Status::BoxBadSize.into();
2361-
}
2362-
u64::from(size32)
2363-
}
2351+
1 => be_u64(src)?,
2352+
_ => u64::from(size32),
23642353
};
23652354
trace!("read_box_header: name: {:?}, size: {}", name, size);
23662355
let mut offset = match size32 {
@@ -2385,7 +2374,13 @@ fn read_box_header<T: ReadBytesExt>(src: &mut T) -> Result<Option<BoxHeader>> {
23852374
} else {
23862375
None
23872376
};
2388-
assert!(offset <= size || size == 0);
2377+
if size != 0 && offset > size {
2378+
if size32 == 1 {
2379+
return Err(Error::from(Status::BoxBadWideSize));
2380+
} else {
2381+
return Err(Error::from(Status::BoxBadSize));
2382+
}
2383+
}
23892384
Ok(Some(BoxHeader {
23902385
name,
23912386
size,

0 commit comments

Comments
 (0)