diff mbox

[FFmpeg-devel,1/2] avcodec/prosumer: Only memset(0) what is needed.

Message ID 20190501194007.23756-1-michael@niedermayer.cc
State Accepted
Commit 17f91c07ef4c04b80d5b09dc3baa64dec161e307
Headers show

Commit Message

Michael Niedermayer May 1, 2019, 7:40 p.m. UTC
Fixes: Timeout (11sec -> 0.08sec)
Fixes: 14406/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PROSUMER_fuzzer-5151210148986880

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

Comments

Michael Niedermayer May 9, 2019, 8:08 p.m. UTC | #1
On Wed, May 01, 2019 at 09:40:06PM +0200, Michael Niedermayer wrote:
> Fixes: Timeout (11sec -> 0.08sec)
> Fixes: 14406/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PROSUMER_fuzzer-5151210148986880
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/prosumer.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

will apply patchset

[...]
diff mbox

Patch

diff --git a/libavcodec/prosumer.c b/libavcodec/prosumer.c
index f064f7bad7..9950519604 100644
--- a/libavcodec/prosumer.c
+++ b/libavcodec/prosumer.c
@@ -153,7 +153,6 @@  static int decode_frame(AVCodecContext *avctx, void *data,
     if (avpkt->size <= 32)
         return AVERROR_INVALIDDATA;
 
-    memset(s->decbuffer, 0, s->size);
     bytestream2_init(&s->gb, avpkt->data, avpkt->size);
     bytestream2_init_writer(&s->pb, s->decbuffer, s->size);
     ret = decompress(&s->gb, AV_RL32(avpkt->data + 28) >> 1, &s->pb, s->lut);
@@ -161,6 +160,10 @@  static int decode_frame(AVCodecContext *avctx, void *data,
         return ret;
     if (bytestream2_get_bytes_left_p(&s->pb) > s->size * (int64_t)avctx->discard_damaged_percentage / 100)
         return AVERROR_INVALIDDATA;
+
+    av_assert0(s->size >= bytestream2_get_bytes_left_p(&s->pb));
+    memset(s->decbuffer + bytestream2_tell_p(&s->pb), 0, bytestream2_get_bytes_left_p(&s->pb));
+
     vertical_predict((uint32_t *)s->decbuffer, 0, (uint32_t *)s->initial_line, s->stride, 1);
     vertical_predict((uint32_t *)s->decbuffer, s->stride, (uint32_t *)s->decbuffer, s->stride, avctx->height - 1);