]> git.sesse.net Git - ffmpeg/commitdiff
avformat/swfdec: Allocate output buffer after reading input
authorMichael Niedermayer <michael@niedermayer.cc>
Wed, 18 Nov 2020 00:29:23 +0000 (01:29 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 24 Dec 2020 14:25:00 +0000 (15:25 +0100)
Fixes: Timeout (>10sec -> 0.26sec)
Fixes: 27419/clusterfuzz-testcase-minimized-ffmpeg_dem_SWF_fuzzer-5678307361947648
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/swfdec.c

index fa11c050cdc3b8e06732686571d9ea04f64ac83e..1463f0ad4d477a9192d56efaaab0b1cf2e3e1bad 100644 (file)
@@ -368,14 +368,21 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
                     ch_id, bmp_fmt, width, height, linesize, len, out_len, colormapsize);
 
             zbuf = av_malloc(len);
-            buf  = av_malloc(out_len);
-            if (!zbuf || !buf) {
+            if (!zbuf) {
                 res = AVERROR(ENOMEM);
                 goto bitmap_end;
             }
 
             len = avio_read(pb, zbuf, len);
-            if (len < 0 || (res = uncompress(buf, &out_len, zbuf, len)) != Z_OK) {
+            if (len < 0)
+                goto bitmap_end_skip;
+
+            buf  = av_malloc(out_len);
+            if (!buf) {
+                res = AVERROR(ENOMEM);
+                goto bitmap_end;
+            }
+            if ((res = uncompress(buf, &out_len, zbuf, len)) != Z_OK) {
                 av_log(s, AV_LOG_WARNING, "Failed to uncompress one bitmap\n");
                 goto bitmap_end_skip;
             }