[FFmpeg-cvslog] avcodec/tdsc: Only reallocate deflatebuffer if its size changed

Michael Niedermayer git at videolan.org
Sat Sep 5 18:49:17 EEST 2020


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Thu Jun 18 12:26:08 2020 +0200| [8dff6da31305ba2f9ebf04e75ad86e1972271760] | committer: Michael Niedermayer

avcodec/tdsc: Only reallocate deflatebuffer if its size changed

Fixes: Timeout (47sec -> 35msec)
Fixes: 23375/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TDSC_fuzzer-5633949497032704

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8dff6da31305ba2f9ebf04e75ad86e1972271760
---

 libavcodec/tdsc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c
index 3617911071..dfd80f6dbc 100644
--- a/libavcodec/tdsc.c
+++ b/libavcodec/tdsc.c
@@ -529,10 +529,15 @@ static int tdsc_decode_frame(AVCodecContext *avctx, void *data,
 
     /* Resize deflate buffer on resolution change */
     if (ctx->width != avctx->width || ctx->height != avctx->height) {
-        ctx->deflatelen = avctx->width * avctx->height * (3 + 1);
-        ret = av_reallocp(&ctx->deflatebuffer, ctx->deflatelen);
-        if (ret < 0)
-            return ret;
+        int deflatelen = avctx->width * avctx->height * (3 + 1);
+        if (deflatelen != ctx->deflatelen) {
+            ctx->deflatelen =deflatelen;
+            ret = av_reallocp(&ctx->deflatebuffer, ctx->deflatelen);
+            if (ret < 0) {
+                ctx->deflatelen = 0;
+                return ret;
+            }
+        }
     }
     dlen = ctx->deflatelen;
 



More information about the ffmpeg-cvslog mailing list