[FFmpeg-devel] [PATCH] avcodec/flashsv: Clear pointers

Michael Niedermayer michael at niedermayer.cc
Thu Jun 9 03:05:48 EEST 2022


Fixes: Use after free
Fixes: 47399/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FLASHSV2_fuzzer-5718646686613504

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

diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c
index 0982161d49..5ea7e56dd5 100644
--- a/libavcodec/flashsv.c
+++ b/libavcodec/flashsv.c
@@ -346,6 +346,9 @@ static int flashsv_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         if (err < 0)
             return err;
         s->keyframedata = avpkt->data;
+        if (s->blocks)
+            memset(s->blocks, 0, (v_blocks + !!v_part) * (h_blocks + !!h_part) *
+                                 sizeof(s->blocks[0]));
     }
     if(s->ver == 2 && !s->blocks)
         s->blocks = av_mallocz((v_blocks + !!v_part) * (h_blocks + !!h_part) *
@@ -554,6 +557,7 @@ static av_cold int flashsv2_decode_end(AVCodecContext *avctx)
     FlashSVContext *s = avctx->priv_data;
 
     av_buffer_unref(&s->keyframedata_buf);
+    s->keyframedata = NULL;
     av_freep(&s->blocks);
     av_freep(&s->keyframe);
     flashsv_decode_end(avctx);
-- 
2.17.1



More information about the ffmpeg-devel mailing list