X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fagm.c;h=bc9dfc02f310af07d236063d3510d4023bf33e93;hb=e13eee37ee3268b0a985ddc74a9bde0179bd553c;hp=2c4c9805e90031843aeb498f6da73a4485a41181;hpb=6ebbfb377f7b6dcbf6a5c85b10109e838bd6e675;p=ffmpeg diff --git a/libavcodec/agm.c b/libavcodec/agm.c index 2c4c9805e90..bc9dfc02f31 100644 --- a/libavcodec/agm.c +++ b/libavcodec/agm.c @@ -423,8 +423,8 @@ static int decode_inter_plane(AGMContext *s, GetBitContext *gb, int size, int map = s->map[x]; if (orig_mv_x >= -32) { - if (y * 8 + mv_y < 0 || y * 8 + mv_y >= h || - x * 8 + mv_x < 0 || x * 8 + mv_x >= w) + if (y * 8 + mv_y < 0 || y * 8 + mv_y + 8 >= h || + x * 8 + mv_x < 0 || x * 8 + mv_x + 8 >= w) return AVERROR_INVALIDDATA; copy_block8(frame->data[plane] + (s->blocks_h - 1 - y) * 8 * frame->linesize[plane] + x * 8, @@ -460,8 +460,8 @@ static int decode_inter_plane(AGMContext *s, GetBitContext *gb, int size, return ret; if (orig_mv_x >= -32) { - if (y * 8 + mv_y < 0 || y * 8 + mv_y >= h || - x * 8 + mv_x < 0 || x * 8 + mv_x >= w) + if (y * 8 + mv_y < 0 || y * 8 + mv_y + 8 > h || + x * 8 + mv_x < 0 || x * 8 + mv_x + 8 > w) return AVERROR_INVALIDDATA; copy_block8(frame->data[plane] + (s->blocks_h - 1 - y) * 8 * frame->linesize[plane] + x * 8, @@ -573,13 +573,16 @@ static int decode_raw_intra_rgb(AVCodecContext *avctx, GetByteContext *gbyte, AV uint8_t *dst = frame->data[0] + (avctx->height - 1) * frame->linesize[0]; uint8_t r = 0, g = 0, b = 0; + if (bytestream2_get_bytes_left(gbyte) < 3 * avctx->width * avctx->height) + return AVERROR_INVALIDDATA; + for (int y = 0; y < avctx->height; y++) { for (int x = 0; x < avctx->width; x++) { - dst[x*3+0] = bytestream2_get_byte(gbyte) + r; + dst[x*3+0] = bytestream2_get_byteu(gbyte) + r; r = dst[x*3+0]; - dst[x*3+1] = bytestream2_get_byte(gbyte) + g; + dst[x*3+1] = bytestream2_get_byteu(gbyte) + g; g = dst[x*3+1]; - dst[x*3+2] = bytestream2_get_byte(gbyte) + b; + dst[x*3+2] = bytestream2_get_byteu(gbyte) + b; b = dst[x*3+2]; } dst -= frame->linesize[0]; @@ -827,7 +830,7 @@ static int decode_intra(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame static int decode_motion_vectors(AVCodecContext *avctx, GetBitContext *gb) { AGMContext *s = avctx->priv_data; - int nb_mvs = ((avctx->height + 15) >> 4) * ((avctx->width + 15) >> 4); + int nb_mvs = ((avctx->coded_height + 15) >> 4) * ((avctx->coded_width + 15) >> 4); int ret, skip = 0, value, map; av_fast_padded_malloc(&s->mvectors, &s->mvectors_size, @@ -1117,6 +1120,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, frame->key_frame = s->key_frame; frame->pict_type = s->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; + if (!s->key_frame) { + if (!s->prev_frame->data[0]) { + av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n"); + return AVERROR_INVALIDDATA; + } + } + if (header) { if (avctx->codec_tag == MKTAG('A', 'G', 'M', '0') || avctx->codec_tag == MKTAG('A', 'G', 'M', '1')) @@ -1186,10 +1196,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, else ret = decode_intra(avctx, gb, frame); } else { - if (!s->prev_frame->data[0]) { - av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n"); - return AVERROR_INVALIDDATA; - } if (s->prev_frame-> width != frame->width || s->prev_frame->height != frame->height) return AVERROR_INVALIDDATA; @@ -1236,6 +1242,11 @@ static av_cold int decode_init(AVCodecContext *avctx) s->dct = avctx->codec_tag != MKTAG('A', 'G', 'M', '4') && avctx->codec_tag != MKTAG('A', 'G', 'M', '5'); + if (!s->rgb && !s->dct) { + if ((avctx->width & 1) || (avctx->height & 1)) + return AVERROR_INVALIDDATA; + } + avctx->idct_algo = FF_IDCT_SIMPLE; ff_idctdsp_init(&s->idsp, avctx); ff_init_scantable(s->idsp.idct_permutation, &s->scantable, ff_zigzag_direct);