[FFmpeg-devel,4/6,RFC] avcodec/motionpixels: Check for end of input in mp_decode_frame_helper()

Submitted by Michael Niedermayer on Aug. 12, 2019, 12:17 a.m.

Details

Message ID 20190812001719.9247-4-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer Aug. 12, 2019, 12:17 a.m.
Improves: Timeout (75sec -> 50sec)
Improves: 16053/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOTIONPIXELS_fuzzer-5647069169057792

Together with the planed reduction in the threshold this would bring this to 20sec and fix the Timeout

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

Patch hide | download patch | download mbox

diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
index 8750a4fa16..ecf32b6144 100644
--- a/libavcodec/motionpixels.c
+++ b/libavcodec/motionpixels.c
@@ -253,7 +253,7 @@  static void mp_decode_line(MotionPixelsContext *mp, GetBitContext *gb, int y)
     }
 }
 
-static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb)
+static int mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb)
 {
     YuvPixel p;
     int y, y0;
@@ -265,6 +265,8 @@  static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb)
             memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));
             p = mp_get_yuv_from_rgb(mp, 0, y);
         } else {
+            if (mp->codes_count > 1 && get_bits_left(gb) < 1)
+                return AVERROR_INVALIDDATA;
             p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb));
             p.y = av_clip_uintp2(p.y, 5);
             if ((y & 3) == 0) {
@@ -280,6 +282,8 @@  static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb)
     for (y0 = 0; y0 < 2; ++y0)
         for (y = y0; y < mp->avctx->height; y += 2)
             mp_decode_line(mp, gb, y);
+
+    return 0;
 }
 
 static int mp_decode_frame(AVCodecContext *avctx,