diff mbox

[FFmpeg-devel] avcodec/gdv: Check compression before allocating frame

Message ID 20171101190259.31977-1-michael@niedermayer.cc
State Accepted
Commit cf5a6c754aa3b67062b8cc60fa244e9c7d82010f
Headers show

Commit Message

Michael Niedermayer Nov. 1, 2017, 7:02 p.m. UTC
Fixes: 2926/clusterfuzz-testcase-4987110014582784

This reduces decoding time from 7 to 4 seconds

The timeout should have been fixed in 0561bd2fc2bff0dbe651d5998e9f129c43d25eb3 but ossfuzz did not close this issue

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

Comments

Paul B Mahol Nov. 1, 2017, 9:44 p.m. UTC | #1
On 11/1/17, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: 2926/clusterfuzz-testcase-4987110014582784
>
> This reduces decoding time from 7 to 4 seconds
>
> The timeout should have been fixed in
> 0561bd2fc2bff0dbe651d5998e9f129c43d25eb3 but ossfuzz did not close this
> issue
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/gdv.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
>

probably ok
Michael Niedermayer Nov. 1, 2017, 11:36 p.m. UTC | #2
On Wed, Nov 01, 2017 at 10:44:10PM +0100, Paul B Mahol wrote:
> On 11/1/17, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > Fixes: 2926/clusterfuzz-testcase-4987110014582784
> >
> > This reduces decoding time from 7 to 4 seconds
> >
> > The timeout should have been fixed in
> > 0561bd2fc2bff0dbe651d5998e9f129c43d25eb3 but ossfuzz did not close this
> > issue
> >
> > Found-by: continuous fuzzing process
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/gdv.c | 15 +++++++++------
> >  1 file changed, 9 insertions(+), 6 deletions(-)
> >
> 
> probably ok

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c
index dc91869edf..e52a637610 100644
--- a/libavcodec/gdv.c
+++ b/libavcodec/gdv.c
@@ -409,17 +409,20 @@  static int gdv_decode_frame(AVCodecContext *avctx, void *data,
     unsigned flags;
     uint8_t *dst;
 
-    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
-        return ret;
-    if (pal && pal_size == AVPALETTE_SIZE)
-        memcpy(gdv->pal, pal, AVPALETTE_SIZE);
-
     bytestream2_init(gb, avpkt->data, avpkt->size);
     bytestream2_init_writer(pb, gdv->frame, gdv->frame_size);
 
     flags = bytestream2_get_le32(gb);
     compression = flags & 0xF;
 
+    if (compression == 4 || compression == 7 || compression > 8)
+        return AVERROR_INVALIDDATA;
+
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+        return ret;
+    if (pal && pal_size == AVPALETTE_SIZE)
+        memcpy(gdv->pal, pal, AVPALETTE_SIZE);
+
     rescale(gdv, gdv->frame, avctx->width, avctx->height,
             !!(flags & 0x10), !!(flags & 0x20));
 
@@ -451,7 +454,7 @@  static int gdv_decode_frame(AVCodecContext *avctx, void *data,
         ret = decompress_68(avctx, flags >> 8, 1);
         break;
     default:
-        return AVERROR_INVALIDDATA;
+        av_assert0(0);
     }
 
     memcpy(frame->data[1], gdv->pal, AVPALETTE_SIZE);