diff --git a/src/oapv.c b/src/oapv.c index 6d29453..78913b6 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -1995,7 +1995,7 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid ret = dec_frm_prepare(ctx, ofrms->frm[frame_cnt].imgb); oapv_assert_g(OAPV_SUCCEEDED(ret), ERR); - int res; + int res, ret_thread; oapv_tpool_t *tpool = ctx->tpool; int parallel_task = 1; int tidx = 0; @@ -2007,11 +2007,11 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid tpool->run(ctx->thread_id[tidx], dec_thread_tile, (void *)ctx->core[tidx]); } - ret = dec_thread_tile((void *)ctx->core[tidx]); + ret_thread = dec_thread_tile((void *)ctx->core[tidx]); for(tidx = 0; tidx < parallel_task - 1; tidx++) { tpool->join(ctx->thread_id[tidx], &res); if(OAPV_FAILED(res)) { - ret = res; + ret_thread = res; } } /****************************************************/ @@ -2025,13 +2025,16 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid if(ret == OAPV_OK && ctx->use_frm_hash) { oapv_imgb_set_md5(ctx->imgb); } - ret = dec_frm_finish(ctx); // FIX-ME + ret = dec_frm_finish(ctx); oapv_assert_g(OAPV_SUCCEEDED(ret), ERR); ofrms->frm[frame_cnt].pbu_type = pbuh.pbu_type; ofrms->frm[frame_cnt].group_id = pbuh.group_id; stat->frm_size[frame_cnt] = pbu_size + 4 /* byte size of 'pbu_size' syntax */; frame_cnt++; + + /* here, check return values of each thread */ + oapv_assert_gv(OAPV_SUCCEEDED(ret_thread), ret, ret_thread, ERR); } else if(pbuh.pbu_type == OAPV_PBU_TYPE_METADATA) { ret = oapvd_vlc_metadata(bs, pbu_size, mid, pbuh.group_id); diff --git a/src/oapv_bs.c b/src/oapv_bs.c index 5ac7a11..81e7db2 100644 --- a/src/oapv_bs.c +++ b/src/oapv_bs.c @@ -146,7 +146,7 @@ int oapv_bsw_write(oapv_bs_t *bs, u32 val, int len) #if ENABLE_DECODER /////////////////////////////////////////////////////////////////////////////// -static void inline bsr_skip_code(oapv_bs_t *bs, int size) +static inline void bsr_skip_code(oapv_bs_t *bs, int size) { oapv_assert(size <= 32); oapv_assert(bs->leftbits >= size); diff --git a/src/oapv_vlc.c b/src/oapv_vlc.c index d0ed8ae..d77df15 100644 --- a/src/oapv_vlc.c +++ b/src/oapv_vlc.c @@ -650,6 +650,8 @@ static int dec_vlc_read_kparam0(oapv_bs_t *bs) k++; } } + oapv_assert_rv(k < 32, -1); /* prevent too large (impossible) k value */ + if(k > 0) { symbol += ((u32)0xFFFFFFFF) >> (32 - k); @@ -736,6 +738,9 @@ static int dec_vlc_read(oapv_bs_t *bs, int k) } } } + + oapv_assert_rv(k < 32, -1); /* prevent too large (impossible) k value */ + if(k > 0) { while(bs->leftbits < k) { symbol += bs->code >> (64 - k); @@ -858,6 +863,8 @@ int oapvd_vlc_ac_coef(oapv_bs_t *bs, s16 *coef, int *kparam_ac) run = dec_vlc_read(bs, k_run); } + oapv_assert_rv(run >= 0, OAPV_ERR_MALFORMED_BITSTREAM); + // here, no need to set 'zero-run' in coef; it's already initialized to zero. scan_pos_offset += run;