[FFmpeg-devel] [PATCH] avcodec/cinepak: check the first slice against the input size before obtaining a frame

Michael Niedermayer michael at niedermayer.cc
Mon Mar 25 18:17:42 EET 2019


Fixes: Timeout (16sec -> 0.5sec)
Fixes: 13854/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CINEPAK_fuzzer-5641061185093632

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

diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index 9b0077402f..18ec19f08d 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -319,6 +319,9 @@ static int cinepak_predecode_check (CinepakContext *s)
 {
     int           num_strips;
     int           encoded_buf_size;
+    int           i;
+    const uint8_t *data = s->data;
+    const uint8_t  *eod = s->data + s->size;
 
     num_strips  = AV_RB16 (&s->data[8]);
     encoded_buf_size = AV_RB24(&s->data[1]);
@@ -353,6 +356,17 @@ static int cinepak_predecode_check (CinepakContext *s)
     if (s->size < 10 + s->sega_film_skip_bytes + num_strips * 12)
         return AVERROR_INVALIDDATA;
 
+    data += 10 + s->sega_film_skip_bytes;
+
+    for (i=0; i < FFMIN(num_strips, 1); i++) {
+        int strip_size = AV_RB24 (&data[1]);
+        if (strip_size < 12 || eod - data < strip_size - strip_size * (int64_t)s->avctx->discard_damaged_percentage / 100)
+            return AVERROR_INVALIDDATA;
+        if (eod - data < strip_size)
+            break;
+        data += strip_size;
+    }
+
     return 0;
 }
 
-- 
2.21.0



More information about the ffmpeg-devel mailing list