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

Missing bounds-checks for VUI Bitstream Restriction Syntax Elements #55

Open
wrv opened this issue Jul 19, 2023 · 3 comments · May be fixed by #66
Open

Missing bounds-checks for VUI Bitstream Restriction Syntax Elements #55

wrv opened this issue Jul 19, 2023 · 3 comments · May be fixed by #66

Comments

@wrv
Copy link

wrv commented Jul 19, 2023

The VUI bitstream restriction syntax elements are not bounds checked: https://github.com/dholroyd/h264-reader/blob/master/src/nal/sps.rs#L803-L812

Expected bounds, according to Annex E.2.1 of the spec:

  • max_bytes_per_pic_denom: [0, 16]
  • max_bits_per_mb_denom: [0, 16]
  • log2_max_mv_length_horizontal: [0, 15]
  • log2_max_mv_length_vertical: [0, 15]
  • max_num_reorder_frames: [0, max_dec_frame_buffering]
  • max_dec_frame_buffering: [max_num_reorder_frames, MaxDpbFrames] where MaxDpbFrames is set by the Level
dholroyd added a commit that referenced this issue Feb 26, 2024
@dholroyd dholroyd linked a pull request Feb 26, 2024 that will close this issue
dholroyd added a commit that referenced this issue Feb 26, 2024
@dholroyd
Copy link
Owner

log2_max_mv_length_horizontal: [0, 15]
log2_max_mv_length_vertical: [0, 15]

This is indeed what more recent versions of the standard specify, e.g. from 2017,

image

Looks like this changed at some point though. Bitstreams I've tested with use the value 16, and going back to a 2003 copy of the spec, it says 16,

image

I don't know when this changed.

It seems that to avoid rejecting real files, these checks should allow 16.

(Discussion of the same confusion on ffmpeg-devel.)

dholroyd added a commit that referenced this issue Feb 27, 2024
@wrv
Copy link
Author

wrv commented Feb 27, 2024

Woah! Thanks for sharing this insight!

Are you familiar with any other syntax elements that have become more restrictive across spec versions?

@dholroyd
Copy link
Owner

I am not aware of other examples; but I would not have investigated if data already used in some tests hadn't been rejected by the new checks.

dholroyd added a commit that referenced this issue Feb 29, 2024
dholroyd added a commit that referenced this issue Mar 1, 2024
dholroyd added a commit that referenced this issue Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants