History

cbs_apv: Check tile component sizes

It was possible for the buffer pointers for the last tile to go over the end of the unit buffer leading to a read overflow during decode of the macroblock layer. Check all tile component sizes to prevent this case and also catch related tile size mismatch errors earlier.

Mark Thompson committed 1 year ago

Commit 9bf54cd1 parent ea457e51 file · +12 −5Browse files

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

Unified · Split

libavcodec/cbs_apv_syntax_template.c+12−5
@@ -189,10 +189,12 @@ static int FUNC(frame_header)(CodedBitstreamContext *ctx, RWContext *rw, · 188 unmodified lines
189189 }
190190
191191 static int FUNC(tile_header)(CodedBitstreamContext *ctx, RWContext *rw,
192− APVRawTileHeader *current, int tile_idx)
192+ APVRawTileHeader *current,
193+ int tile_idx, uint32_t tile_size)
193194 {
194195 const CodedBitstreamAPVContext *priv = ctx->priv_data;
195196 uint16_t expected_tile_header_size;
197+ uint32_t tile_size_remaining;
196198 uint8_t max_qp;
197199 int err;
198200
@@ -203,8 +205,10 @@ static int FUNC(tile_header)(CodedBitstreamContext *ctx, RWContext *rw, · 4 unmodified lines
203205
204206 u(16, tile_index, tile_idx, tile_idx);
205207
208+ tile_size_remaining = tile_size - current->tile_header_size;
206209 for (int c = 0; c < priv->num_comp; c++) {
207− us(32, tile_data_size[c], 1, MAX_UINT_BITS(32), 1, c);
210+ us(32, tile_data_size[c], 1, tile_size_remaining, 1, c);
211+ tile_size_remaining -= current->tile_data_size[c];
208212 }
209213
210214 max_qp = 3 + priv->bit_depth * 6;
@@ -218,12 +222,14 @@ static int FUNC(tile_header)(CodedBitstreamContext *ctx, RWContext *rw, · 7 unmodified lines
218222 }
219223
220224 static int FUNC(tile)(CodedBitstreamContext *ctx, RWContext *rw,
221− APVRawTile *current, int tile_idx)
225+ APVRawTile *current,
226+ int tile_idx, uint32_t tile_size)
222227 {
223228 const CodedBitstreamAPVContext *priv = ctx->priv_data;
224229 int err;
225230
226− CHECK(FUNC(tile_header)(ctx, rw, &current->tile_header, tile_idx));
231+ CHECK(FUNC(tile_header)(ctx, rw, &current->tile_header,
232+ tile_idx, tile_size));
227233
228234 for (int c = 0; c < priv->num_comp; c++) {
229235 uint32_t comp_size = current->tile_header.tile_data_size[c];
@@ -257,7 +263,8 @@ static int FUNC(frame)(CodedBitstreamContext *ctx, RWContext *rw, · 27 unmodified lines
257263 for (int t = 0; t < priv->tile_info.num_tiles; t++) {
258264 us(32, tile_size[t], 10, MAX_UINT_BITS(32), 1, t);
259265
260− CHECK(FUNC(tile)(ctx, rw, &current->tile[t], t));
266+ CHECK(FUNC(tile)(ctx, rw, &current->tile[t],
267+ t, current->tile_size[t]));
261268 }
262269
263270 CHECK(FUNC(filler)(ctx, rw, &current->filler));

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