X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fvc1dec.c;h=efcb169c8f03b414f6581eb22ed3248aac7f2327;hb=4156df59f59626f60186a4effed80f60c9c4e8cc;hp=87846449ec720b7836ed2f7fcd5f82faade057c8;hpb=1e3718e2a1e70ae13785c566a197552eac7eda39;p=ffmpeg diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 87846449ec7..efcb169c8f0 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -59,20 +59,6 @@ static const int offset_table2[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }; * @{ */ -/** - * Imode types - * @{ - */ -enum Imode { - IMODE_RAW, - IMODE_NORM2, - IMODE_DIFF2, - IMODE_NORM6, - IMODE_DIFF6, - IMODE_ROWSKIP, - IMODE_COLSKIP -}; -/** @} */ //imode defines static void init_block_index(VC1Context *v) { @@ -391,7 +377,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) srcV = s->current_picture.f.data[2]; luty = v->curr_luty; lutuv = v->curr_lutuv; - use_ic = v->curr_use_ic; + use_ic = *v->curr_use_ic; } else { srcY = s->last_picture.f.data[0]; srcU = s->last_picture.f.data[1]; @@ -585,7 +571,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) if (v->field_mode && (v->cur_field_type != v->ref_field_type[dir]) && v->second_field) { srcY = s->current_picture.f.data[0]; luty = v->curr_luty; - use_ic = v->curr_use_ic; + use_ic = *v->curr_use_ic; } else { srcY = s->last_picture.f.data[0]; luty = v->last_luty; @@ -887,7 +873,7 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir) srcU = s->current_picture.f.data[1]; srcV = s->current_picture.f.data[2]; lutuv = v->curr_lutuv; - use_ic = v->curr_use_ic; + use_ic = *v->curr_use_ic; } else { srcU = s->last_picture.f.data[1]; srcV = s->last_picture.f.data[2]; @@ -5288,7 +5274,7 @@ static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7]) c[6] = 1 << 16; } -static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd) +static int vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd) { AVCodecContext *avctx = v->s.avctx; int sprite, i; @@ -5332,7 +5318,7 @@ static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd) sd->effect_pcount2 = get_bits(gb, 16); if (sd->effect_pcount2 > 10) { av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n"); - return; + return AVERROR_INVALIDDATA; } else if (sd->effect_pcount2) { i = -1; av_log(avctx, AV_LOG_DEBUG, "Effect params 2: "); @@ -5349,10 +5335,14 @@ static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd) av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n"); if (get_bits_count(gb) >= gb->size_in_bits + - (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE ? 64 : 0)) + (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE ? 64 : 0)) { av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n"); + return AVERROR_INVALIDDATA; + } if (get_bits_count(gb) < gb->size_in_bits - 8) av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n"); + + return 0; } static void vc1_draw_sprites(VC1Context *v, SpriteData* sd) @@ -5364,7 +5354,7 @@ static void vc1_draw_sprites(VC1Context *v, SpriteData* sd) int ysub[2]; MpegEncContext *s = &v->s; - for (i = 0; i < 2; i++) { + for (i = 0; i <= v->two_sprites; i++) { xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16); xadv[i] = sd->coefs[i][0]; if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i]) @@ -5442,7 +5432,7 @@ static void vc1_draw_sprites(VC1Context *v, SpriteData* sd) } if (!plane) { - for (i = 0; i < 2; i++) { + for (i = 0; i <= v->two_sprites; i++) { xoff[i] >>= 1; yoff[i] >>= 1; } @@ -5459,7 +5449,11 @@ static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb) AVCodecContext *avctx = s->avctx; SpriteData sd; - vc1_parse_sprites(v, gb, &sd); + memset(&sd, 0, sizeof(sd)); + + ret = vc1_parse_sprites(v, gb, &sd); + if (ret < 0) + return ret; if (!s->current_picture.f.data[0]) { av_log(avctx, AV_LOG_ERROR, "Got no sprites\n"); @@ -5504,14 +5498,15 @@ av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v) { MpegEncContext *s = &v->s; int i; + int mb_height = FFALIGN(s->mb_height, 2); /* Allocate mb bitplanes */ - v->mv_type_mb_plane = av_malloc (s->mb_stride * s->mb_height); - v->direct_mb_plane = av_malloc (s->mb_stride * s->mb_height); - v->forward_mb_plane = av_malloc (s->mb_stride * s->mb_height); - v->fieldtx_plane = av_mallocz(s->mb_stride * s->mb_height); - v->acpred_plane = av_malloc (s->mb_stride * s->mb_height); - v->over_flags_plane = av_malloc (s->mb_stride * s->mb_height); + v->mv_type_mb_plane = av_malloc (s->mb_stride * mb_height); + v->direct_mb_plane = av_malloc (s->mb_stride * mb_height); + v->forward_mb_plane = av_malloc (s->mb_stride * mb_height); + v->fieldtx_plane = av_mallocz(s->mb_stride * mb_height); + v->acpred_plane = av_malloc (s->mb_stride * mb_height); + v->over_flags_plane = av_malloc (s->mb_stride * mb_height); v->n_allocated_blks = s->mb_width + 2; v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks); @@ -5521,24 +5516,24 @@ av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v) v->ttblk = v->ttblk_base + s->mb_stride; v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride); v->is_intra = v->is_intra_base + s->mb_stride; - v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride); + v->luma_mv_base = av_mallocz(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride); v->luma_mv = v->luma_mv_base + s->mb_stride; /* allocate block type info in that way so it could be used with s->block_index[] */ - v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); + v->mb_type_base = av_malloc(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); v->mb_type[0] = v->mb_type_base + s->b8_stride + 1; - v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1; - v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1); + v->mb_type[1] = v->mb_type_base + s->b8_stride * (mb_height * 2 + 1) + s->mb_stride + 1; + v->mb_type[2] = v->mb_type[1] + s->mb_stride * (mb_height + 1); /* allocate memory to store block level MV info */ - v->blk_mv_type_base = av_mallocz( s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); + v->blk_mv_type_base = av_mallocz( s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1; - v->mv_f_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2)); + v->mv_f_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2)); v->mv_f[0] = v->mv_f_base + s->b8_stride + 1; - v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); - v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2)); + v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); + v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2)); v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1; - v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); + v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); /* Init coded blocks info */ if (v->profile == PROFILE_ADVANCED) { @@ -5863,7 +5858,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, buf_size3 << 3); /* assuming that the field marker is at the exact middle, hope it's correct */ - slices[n_slices].mby_start = s->mb_height >> 1; + slices[n_slices].mby_start = s->mb_height + 1 >> 1; n_slices1 = n_slices - 1; // index of the last slice of the first field n_slices++; break; @@ -5914,7 +5909,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); - slices[n_slices].mby_start = s->mb_height >> 1; + slices[n_slices].mby_start = s->mb_height + 1 >> 1; n_slices1 = n_slices - 1; n_slices++; } @@ -6111,6 +6106,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, continue; } v->second_field = 1; + av_assert0((s->mb_height & 1) == 0); v->blocks_off = s->b8_stride * (s->mb_height&~1); v->mb_off = s->mb_stride * s->mb_height >> 1; } else {