1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/smacker: Move buffer allocation to later

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>
This commit is contained in:
Michael Niedermayer
2025-07-03 03:01:11 +02:00
parent 6b028859d9
commit 9899c8c00b

View File

@ -641,10 +641,6 @@ static int smka_decode_frame(AVCodecContext *avctx, AVFrame *frame,
"The buffer does not contain an integer number of samples\n"); "The buffer does not contain an integer number of samples\n");
return AVERROR_INVALIDDATA; 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 // Initialize
for(i = 0; i < (1 << (bits + stereo)); i++) { for(i = 0; i < (1 << (bits + stereo)); i++) {
@ -666,6 +662,12 @@ static int smka_decode_frame(AVCodecContext *avctx, AVFrame *frame,
} else } else
values[i] = h.entries[0].value; 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 */ /* this codec relies on wraparound instead of clipping audio */
if(bits) { //decode 16-bit data if(bits) { //decode 16-bit data
for(i = stereo; i >= 0; i--) for(i = stereo; i >= 0; i--)