[FFmpeg-devel,1/4] avcodec/agm: Check for reference frame earlier

Submitted by Michael Niedermayer on Oct. 4, 2019, 5:59 p.m.

Details

Message ID 20191004175942.14310-1-michael@niedermayer.cc
State Accepted
Commit 315a4459334fdc1e6b18733fb63439e9d090cebd
Headers show

Commit Message

Michael Niedermayer Oct. 4, 2019, 5:59 p.m.
Fixes: Timeout (14sec -  120ms)
Fixes: 17824/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5639825457152000

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/agm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer Oct. 20, 2019, 5:25 p.m.
On Fri, Oct 04, 2019 at 07:59:39PM +0200, Michael Niedermayer wrote:
> Fixes: Timeout (14sec -  120ms)
> Fixes: 17824/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5639825457152000
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/agm.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)

will apply remaining parts of patchset

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/agm.c b/libavcodec/agm.c
index 2c4c9805e9..3b2c21e9a7 100644
--- a/libavcodec/agm.c
+++ b/libavcodec/agm.c
@@ -1117,6 +1117,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 +1193,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;