[FFmpeg-devel] [PATCH 1/3] avcodec/shorten: Clear the additionally allocated space on realloc

Michael Niedermayer michael at niedermayer.cc
Thu Jul 24 19:40:17 EEST 2025


Fixes: use of uninitialized memory
Fixes: 421954767/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SHORTEN_fuzzer-515682786246656

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/shorten.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index ad2e7588d69..bed92936801 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -584,7 +584,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         if (avpkt->size) {
             int max_framesize = s->blocksize * s->channels * 8;
             void *tmp_ptr;
-
+            unsigned old_allocated_bitstream_size = s->allocated_bitstream_size;
             tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size,
                                       max_framesize + AV_INPUT_BUFFER_PADDING_SIZE);
             if (!tmp_ptr) {
@@ -592,9 +592,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                 return AVERROR(ENOMEM);
             }
             s->bitstream = tmp_ptr;
-            if (max_framesize > s->max_framesize)
-                memset(s->bitstream + s->max_framesize, 0, (max_framesize - s->max_framesize) +
-                                                            AV_INPUT_BUFFER_PADDING_SIZE);
+            if (s->allocated_bitstream_size > old_allocated_bitstream_size)
+                memset(s->bitstream + old_allocated_bitstream_size, 0, s->allocated_bitstream_size - old_allocated_bitstream_size);
             s->max_framesize = FFMAX(s->max_framesize, max_framesize);
             *got_frame_ptr = 0;
             goto finish_frame;
-- 
2.50.1



More information about the ffmpeg-devel mailing list