diff mbox

[FFmpeg-devel] avcodec/dxtory: Check slice sizes before allocating image

Message ID 20190316163211.29288-1-michael@niedermayer.cc
State Accepted
Commit d92034a06aadd057b3d3b08a1bd3cb8b1aab0898
Headers show

Commit Message

Michael Niedermayer March 16, 2019, 4:32 p.m. UTC
Fixes: Timeout (26sec -> 2sec)
Fixes: 13612/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DXTORY_fuzzer-5676845977042944

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

Comments

Michael Niedermayer March 25, 2019, 2 p.m. UTC | #1
On Sat, Mar 16, 2019 at 05:32:11PM +0100, Michael Niedermayer wrote:
> Fixes: Timeout (26sec -> 2sec)
> Fixes: 13612/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DXTORY_fuzzer-5676845977042944
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/dxtory.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)

will apply

[...]
diff mbox

Patch

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 285ca38efb..7024b315d1 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -272,10 +272,11 @@  static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic,
                             setup_lru_func setup_lru,
                             enum AVPixelFormat fmt)
 {
-    GetByteContext gb;
+    GetByteContext gb, gb_check;
     GetBitContext  gb2;
     int nslices, slice, line = 0;
     uint32_t off, slice_size;
+    uint64_t off_check;
     uint8_t lru[3][8];
     int ret;
 
@@ -283,6 +284,13 @@  static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic,
     if (ret < 0)
         return ret;
 
+    off_check = off;
+    gb_check = gb;
+    for (slice = 0; slice < nslices; slice++)
+        off_check += bytestream2_get_le32(&gb_check);
+    if (off_check - avctx->discard_damaged_percentage*off_check/100 > src_size)
+        return AVERROR_INVALIDDATA;
+
     avctx->pix_fmt = fmt;
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;