Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/improvements for the H.264 parser #82

Merged
merged 15 commits into from
Jul 11, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
codec/h264/parser: prevent potential overflow while multiplying
Revealed by fuzzing.
Gnurou committed Jul 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4d83b88dbdd04be76c95b935fd9250e4e9a98677
23 changes: 11 additions & 12 deletions src/codec/h264/parser.rs
Original file line number Diff line number Diff line change
@@ -2043,23 +2043,22 @@ impl Parser {
Parser::parse_vui(&mut r, &mut sps)?;
}

let mut width = sps.width();
let mut height = sps.height();

if sps.frame_cropping_flag {
let (crop_unit_x, crop_unit_y) = sps.crop_unit_x_y();

width = width
.checked_sub(
(sps.frame_crop_left_offset + sps.frame_crop_right_offset) * crop_unit_x,
)
let width = sps
.frame_crop_left_offset
.checked_add(sps.frame_crop_right_offset)
.and_then(|r| r.checked_mul(crop_unit_x))
.and_then(|r| sps.width().checked_sub(r))
.ok_or(anyhow!("Invalid frame crop width"))?;

height = height
.checked_sub(
(sps.frame_crop_top_offset + sps.frame_crop_bottom_offset) * crop_unit_y,
)
.ok_or(anyhow!("Invalid frame crop height"))?;
let height = sps
.frame_crop_top_offset
.checked_add(sps.frame_crop_bottom_offset)
.and_then(|r| r.checked_mul(crop_unit_y))
.and_then(|r| sps.height().checked_sub(r))
.ok_or(anyhow!("invalid frame crop height"))?;

sps.crop_rect_width = width;
sps.crop_rect_height = height;