avcodec/cinepak: Check slice_size before allocating image
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 27 Apr 2019 21:37:26 +0000 (23:37 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Tue, 30 Apr 2019 19:24:04 +0000 (21:24 +0200)
Fixes: Timeout (16sec -> 125msec)
Fixes: 14283/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CINEPAK_fuzzer-5742851457024000

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/cinepak.c

index 9b00774..d26c505 100644 (file)
@@ -353,6 +353,13 @@ static int cinepak_predecode_check (CinepakContext *s)
     if (s->size < 10 + s->sega_film_skip_bytes + num_strips * 12)
         return AVERROR_INVALIDDATA;
 
+    if (num_strips) {
+        uint8_t *data = s->data + 10 + s->sega_film_skip_bytes;
+        int strip_size = AV_RB24 (data + 1);
+        if (strip_size < 12 || strip_size > encoded_buf_size)
+            return AVERROR_INVALIDDATA;
+    }
+
     return 0;
 }