[FFmpeg-devel] avcodec/dsicinvideo: check the amount decoded by cin_decode_huffman()

Submitted by Michael Niedermayer on April 15, 2019, 5:28 p.m.

Details

Message ID 20190415172818.7982-1-michael@niedermayer.cc
State Accepted
Commit fee666104519ec7889ec3242404857bed7598a36
Headers show

Commit Message

Michael Niedermayer April 15, 2019, 5:28 p.m.
Fixes: Timeout (158sec -> 36sec)
Fixes: 14214/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DSICINVIDEO_fuzzer-5633569034076160

This is untested with valid cin files as none of the files i found cover the changed
codepath

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

Comments

Michael Niedermayer April 24, 2019, 10:40 a.m.
On Mon, Apr 15, 2019 at 07:28:18PM +0200, Michael Niedermayer wrote:
> Fixes: Timeout (158sec -> 36sec)
> Fixes: 14214/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DSICINVIDEO_fuzzer-5633569034076160
> 
> This is untested with valid cin files as none of the files i found cover the changed
> codepath
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/dsicinvideo.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

will apply

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/dsicinvideo.c b/libavcodec/dsicinvideo.c
index 37175d67b2..d422df068d 100644
--- a/libavcodec/dsicinvideo.c
+++ b/libavcodec/dsicinvideo.c
@@ -266,8 +266,11 @@  static int cinvideo_decode_frame(AVCodecContext *avctx,
                              cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
         break;
     case 37:
-        cin_decode_huffman(buf, bitmap_frame_size,
+        res = cin_decode_huffman(buf, bitmap_frame_size,
                            cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
+
+        if (cin->bitmap_size - avctx->discard_damaged_percentage*cin->bitmap_size/100 > res)
+            return AVERROR_INVALIDDATA;
         break;
     case 38:
         res = cin_decode_lzss(buf, bitmap_frame_size,