X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fvp3.c;h=f167acf4eefa7c79ecd7e119e4cac40c3ba2e30a;hb=fe9242204d33db070b8a9d907d93c9ead8a6f3ee;hp=86e5852e32935e8da4a21fe6333c9d11e7efa189;hpb=d61f93bf04eb90d3998d654e233fcaa87e86768a;p=ffmpeg diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 86e5852e329..f167acf4eef 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -1071,6 +1071,9 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb) s->dct_tokens[0][0] = s->dct_tokens_base; + if (get_bits_left(gb) < 16) + return AVERROR_INVALIDDATA; + /* fetch the DC table indexes */ dc_y_table = get_bits(gb, 4); dc_c_table = get_bits(gb, 4); @@ -1080,6 +1083,8 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb) 0, residual_eob_run); if (residual_eob_run < 0) return residual_eob_run; + if (get_bits_left(gb) < 8) + return AVERROR_INVALIDDATA; /* reverse prediction of the Y-plane DC coefficients */ reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]); @@ -1102,6 +1107,8 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb) s->fragment_width[1], s->fragment_height[1]); } + if (get_bits_left(gb) < 8) + return AVERROR_INVALIDDATA; /* fetch the AC table indexes */ ac_y_table = get_bits(gb, 4); ac_c_table = get_bits(gb, 4); @@ -1996,6 +2003,7 @@ static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; Vp3DecodeContext *s = avctx->priv_data; @@ -2169,12 +2177,12 @@ static int vp3_decode_frame(AVCodecContext *avctx, /* output frame, offset as needed */ if ((ret = av_frame_ref(data, s->current_frame.f)) < 0) return ret; - for (i = 0; i < 3; i++) { - AVFrame *dst = data; - int off = (s->offset_x >> (i && s->chroma_y_shift)) + - (s->offset_y >> (i && s->chroma_y_shift)) * dst->linesize[i]; - dst->data[i] += off; - } + + frame->crop_left = s->offset_x; + frame->crop_right = avctx->coded_width - avctx->width - s->offset_x; + frame->crop_top = s->offset_y; + frame->crop_bottom = avctx->coded_height - avctx->height - s->offset_y; + *got_frame = 1; if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) { @@ -2344,16 +2352,6 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) // to normal axis ([0,0] upper left) s->offset_x = offset_x; s->offset_y = s->height - visible_height - offset_y; - - if ((s->offset_x & 0x1F) && !(avctx->flags & AV_CODEC_FLAG_UNALIGNED)) { - s->offset_x &= ~0x1F; - if (!s->offset_x_warned) { - s->offset_x_warned = 1; - av_log(avctx, AV_LOG_WARNING, "Reducing offset_x from %d to %d" - "chroma samples to preserve alignment.\n", - offset_x, s->offset_x); - } - } } if (colorspace == 1) @@ -2566,7 +2564,8 @@ AVCodec ff_theora_decoder = { AV_CODEC_CAP_FRAME_THREADS, .flush = vp3_decode_flush, .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy), - .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context) + .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context), + .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING, }; #endif