Skip to content

Commit

Permalink
ctx->frame_worker shouldn't be partially allocated
Browse files Browse the repository at this point in the history
init_decoder() should not leave ctx->frame_worker partially allocated.
It should fully allocate ctx->frame_worker on success, and set
ctx->frame_worker to NULL on failure.

This bug was found by Philippe Antoine <[email protected]> using
nallocfuzz (see google/oss-fuzz#9902).

Change-Id: I1ab5bb26e396f2f1d9f7e42f570563403f0e2be2
  • Loading branch information
wantehchang committed Jun 23, 2023
1 parent 57dd20a commit e0f8553
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions av1/av1_dx_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) {
AV1Decoder *const pbi = frame_worker_data->pbi;
aom_free(pbi->common.tpl_mvs);
pbi->common.tpl_mvs = NULL;
av1_remove_common(&frame_worker_data->pbi->common);
av1_remove_common(&pbi->common);
av1_free_cdef_buffers(&pbi->common, &pbi->cdef_worker, &pbi->cdef_sync);
av1_free_cdef_sync(&pbi->cdef_sync);
av1_free_restoration_buffers(&pbi->common);
Expand Down Expand Up @@ -457,18 +457,24 @@ static aom_codec_err_t init_decoder(aom_codec_alg_priv_t *ctx) {
}

AVxWorker *const worker = ctx->frame_worker;
FrameWorkerData *frame_worker_data = NULL;
winterface->init(worker);
worker->thread_name = "aom frameworker";
worker->data1 = aom_memalign(32, sizeof(FrameWorkerData));
if (worker->data1 == NULL) {
winterface->end(worker);
aom_free(worker);
ctx->frame_worker = NULL;
set_error_detail(ctx, "Failed to allocate frame_worker_data");
return AOM_CODEC_MEM_ERROR;
}
frame_worker_data = (FrameWorkerData *)worker->data1;
FrameWorkerData *frame_worker_data = (FrameWorkerData *)worker->data1;
frame_worker_data->pbi = av1_decoder_create(ctx->buffer_pool);
if (frame_worker_data->pbi == NULL) {
set_error_detail(ctx, "Failed to allocate frame_worker_data");
winterface->end(worker);
aom_free(frame_worker_data);
aom_free(worker);
ctx->frame_worker = NULL;
set_error_detail(ctx, "Failed to allocate frame_worker_data->pbi");
return AOM_CODEC_MEM_ERROR;
}
frame_worker_data->frame_context_ready = 0;
Expand Down

0 comments on commit e0f8553

Please sign in to comment.