Skip to content

Commit 9bf54cd

Browse files
committed
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.
1 parent ea457e5 commit 9bf54cd

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

libavcodec/cbs_apv_syntax_template.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ static int FUNC(frame_header)(CodedBitstreamContext *ctx, RWContext *rw,
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,
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,
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,
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));

0 commit comments

Comments
 (0)