Skip to content

Commit f2d9680

Browse files
padenotkinetiknz
authored andcommitted
Fix integer overflow in composition time calculation
Use checked_add() instead of unchecked addition when calculating start_composition and end_composition times. Malformed MP4 files could trigger integer overflow, causing a panic in debug builds. The fix returns None when overflow is detected, allowing the error to propagate gracefully rather than crashing. Fixes Mozilla bug 2014838.
1 parent 8422a9d commit f2d9680

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

mp4parse/src/unstable.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,23 @@ pub fn create_sample_table(
239239

240240
let start_decode = decode_time;
241241

242-
sample.start_composition = CheckedInteger(track_offset_time.0 + start_composition?.0);
243-
sample.end_composition = CheckedInteger(track_offset_time.0 + end_composition?.0);
242+
let start_composition_val: i64 = match start_composition {
243+
Some(sc) => sc.0,
244+
None => return None,
245+
};
246+
let end_composition_val: i64 = match end_composition {
247+
Some(ec) => ec.0,
248+
None => return None,
249+
};
250+
251+
let track_offset: i64 = track_offset_time.0;
252+
253+
sample.start_composition = CheckedInteger(
254+
track_offset.checked_add(start_composition_val)?
255+
);
256+
sample.end_composition = CheckedInteger(
257+
track_offset.checked_add(end_composition_val)?
258+
);
244259
sample.start_decode = CheckedInteger(start_decode.0);
245260
}
246261

0 commit comments

Comments
 (0)