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

Submitted by Michael Niedermayer on March 25, 2019, 4:17 p.m.

Details

Message ID 20190325161742.23518-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer March 25, 2019, 4:17 p.m.
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@niedermayer.cc>
---
 libavcodec/cinepak.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Tomas Härdin March 28, 2019, 10:39 a.m.
> +    data += 10 + s->sega_film_skip_bytes;
> +
> +    for (i=0; i < FFMIN(num_strips, 1); i++) {

if (num_strips) maybe? Or is this supposed to be FFMAX perhaps?

> +        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)

Kind of a long line

/Tomas

Patch hide | download patch | download mbox

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;
 }