avcodec/agm: More completely check size before using it
authorMichael Niedermayer <michael@niedermayer.cc>
Wed, 3 Apr 2019 00:12:28 +0000 (02:12 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 4 Apr 2019 09:31:17 +0000 (11:31 +0200)
Fixes: out of array access
Fixes: 13997/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5701427252428800

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/agm.c

index b0e8b80..2d20922 100644 (file)
@@ -562,7 +562,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 
     for (int i = 0; i < 3; i++)
         s->size[i] = bytestream2_get_le32(gbyte);
-    if (32LL + s->size[0] + s->size[1] + s->size[2] > avpkt->size)
+    if (s->size[0] < 0 || s->size[1] < 0 || s->size[2] < 0 ||
+        32LL + s->size[0] + s->size[1] + s->size[2] > avpkt->size)
         return AVERROR_INVALIDDATA;
 
     if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)