]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/tdsc: Only reallocate deflatebuffer if its size changed
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 18 Jun 2020 10:26:08 +0000 (12:26 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 5 Sep 2020 15:48:59 +0000 (17:48 +0200)
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@niedermayer.cc>
libavcodec/tdsc.c

index 3617911071ad1bc6f90ca7e98abcd52b42562599..dfd80f6dbc2a8a4f2078c64212cb6efd2d257c77 100644 (file)
@@ -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;