dholroyd / h264-reader

Rust reader for H264 bitsream syntax
Apache License 2.0
72 stars 25 forks source link

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

Open wrv opened 1 year ago

wrv commented 1 year ago

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:

dholroyd commented 6 months ago

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.)

wrv commented 6 months ago

Woah! Thanks for sharing this insight!

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

dholroyd commented 6 months ago

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.