This commit adds value range checks to cbs_vp8_read_unsigned_le, migrates fixed() to use it, and enforces little-endian consistency for all read methods.
Unified · Split
| @@ -181,9 +181,11 @@ static int cbs_vp8_bool_decoder_read_signed( · 180 unmodified lines | ||
| 181 | 181 | return 0; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | −static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext *gbc, | |
| 185 | − int width, const char *name, | |
| 186 | − const int *subscripts, uint32_t *write_to) | |
| 184 | +static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, | |
| 185 | + GetBitContext *gbc, int width, | |
| 186 | + const char *name, const int *subscripts, | |
| 187 | + uint32_t *write_to, uint32_t range_min, | |
| 188 | + uint32_t range_max) | |
| 187 | 189 | { |
| 188 | 190 | int32_t value; |
| 189 | 191 | |
| @@ -200,6 +202,14 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext *g · 10 unmodified lines | ||
| 200 | 202 | |
| 201 | 203 | CBS_TRACE_READ_END(); |
| 202 | 204 | |
| 205 | + if (value < range_min || value > range_max) { | |
| 206 | + av_log(ctx->log_ctx, AV_LOG_ERROR, | |
| 207 | + "%s out of range: " | |
| 208 | + "%" PRIu32 ", but must be in [%" PRIu32 ",%" PRIu32 "].\n", | |
| 209 | + name, value, range_min, range_max); | |
| 210 | + return AVERROR_INVALIDDATA; | |
| 211 | + } | |
| 212 | + | |
| 203 | 213 | *write_to = value; |
| 204 | 214 | return 0; |
| 205 | 215 | } |
| @@ -246,15 +256,16 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext *g · 40 unmodified lines | ||
| 246 | 256 | do { \ |
| 247 | 257 | uint32_t value; \ |
| 248 | 258 | CHECK(cbs_vp8_read_unsigned_le(ctx, rw, width, #name, \ |
| 249 | − SUBSCRIPTS(subs, __VA_ARGS__), &value)); \ | |
| 259 | + SUBSCRIPTS(subs, __VA_ARGS__), &value, \ | |
| 260 | + 0, MAX_UINT_BITS(width))); \ | |
| 250 | 261 | current->name = value; \ |
| 251 | 262 | } while (0) |
| 252 | 263 | |
| 253 | 264 | #define fixed(width, name, value) \ |
| 254 | 265 | do { \ |
| 255 | 266 | uint32_t fixed_value; \ |
| 256 | − CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, 0, &fixed_value, \ | |
| 257 | − value, value)); \ | |
| 267 | + CHECK(cbs_vp8_read_unsigned_le(ctx, rw, width, #name, 0, &fixed_value, \ | |
| 268 | + value, value)); \ | |
| 258 | 269 | } while (0) |
| 259 | 270 | |
| 260 | 271 | #define bc_unsigned_subs(width, prob, enable_trace, name, subs, ...) \ |