avcodec/smacker: Move buffer allocation to later
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 3 Jul 2025 01:01:11 +0000 (03:01 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 4 Aug 2025 15:10:14 +0000 (17:10 +0200)
Reduces allocations on random input
Fixes: 421650030/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMACKAUD_fuzzer-6144441767493632

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 9899c8c00bb7674fe3cf5c8483b522c6c78e1248)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/smacker.c

index ffa0820f52f022d218b1922e414ad909df747cd6..fef6fd0dccca88fc68706e2f753e7a53135d1092 100644 (file)
@@ -645,10 +645,6 @@ static int smka_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                "The buffer does not contain an integer number of samples\n");
         return AVERROR_INVALIDDATA;
     }
-    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
-        return ret;
-    samples  = (int16_t *)frame->data[0];
-    samples8 =            frame->data[0];
 
     // Initialize
     for(i = 0; i < (1 << (bits + stereo)); i++) {
@@ -670,6 +666,12 @@ static int smka_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         } else
             values[i] = h.entries[0].value;
     }
+
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+        return ret;
+    samples  = (int16_t *)frame->data[0];
+    samples8 =            frame->data[0];
+
     /* this codec relies on wraparound instead of clipping audio */
     if(bits) { //decode 16-bit data
         for(i = stereo; i >= 0; i--)