History

avcodec/cbs_vp8: Use little endian in fixed()

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.

Dai, Jianhui J committed 2 years ago

Commit 63dea3c1 parent ea2e0e91 file · +17 −6Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/cbs_vp8.c+17−6
@@ -181,9 +181,11 @@ static int cbs_vp8_bool_decoder_read_signed( · 180 unmodified lines
181181 return 0;
182182 }
183183
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)
187189 {
188190 int32_t value;
189191
@@ -200,6 +202,14 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext *g · 10 unmodified lines
200202
201203 CBS_TRACE_READ_END();
202204
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+
203213 *write_to = value;
204214 return 0;
205215 }
@@ -246,15 +256,16 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext *g · 40 unmodified lines
246256 do { \
247257 uint32_t value; \
248258 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))); \
250261 current->name = value; \
251262 } while (0)
252263
253264 #define fixed(width, name, value) \
254265 do { \
255266 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)); \
258269 } while (0)
259270
260271 #define bc_unsigned_subs(width, prob, enable_trace, name, subs, ...) \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t