[FFmpeg-devel,2/2] avcodec/vmnc: Check available space against chunks before reget_buffer()

Submitted by Michael Niedermayer on May 17, 2019, 10:27 p.m.

Details

Message ID 20190517222733.20113-2-michael@niedermayer.cc
State Accepted
Commit 279d9a84af37cc1a7cf79c1cd667105eeb948611
Headers show

Commit Message

Michael Niedermayer May 17, 2019, 10:27 p.m.
Fixes: Timeout (16sec -> 60ms)
Fixes: 14673/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VMNC_fuzzer-5640217517621248

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

Patch hide | download patch | download mbox

diff --git a/libavcodec/vmnc.c b/libavcodec/vmnc.c
index 30b1414e49..e273043311 100644
--- a/libavcodec/vmnc.c
+++ b/libavcodec/vmnc.c
@@ -333,11 +333,15 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     uint8_t *outptr;
     int dx, dy, w, h, depth, enc, chunks, res, size_left, ret;
 
+    bytestream2_init(gb, buf, buf_size);
+    bytestream2_skip(gb, 2);
+    chunks = bytestream2_get_be16(gb);
+    if (12LL * chunks > bytestream2_get_bytes_left(gb))
+        return AVERROR_INVALIDDATA;
+
     if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
         return ret;
 
-    bytestream2_init(gb, buf, buf_size);
-
     c->pic->key_frame = 0;
     c->pic->pict_type = AV_PICTURE_TYPE_P;
 
@@ -369,8 +373,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             }
         }
     }
-    bytestream2_skip(gb, 2);
-    chunks = bytestream2_get_be16(gb);
+
     while (chunks--) {
         if (bytestream2_get_bytes_left(gb) < 12) {
             av_log(avctx, AV_LOG_ERROR, "Premature end of data!\n");