avcodec/tta: Check 24bit scaling for overflow

Fixes: signed integer overflow: -8427924 * 256 cannot be represented in type 'int'
Fixes: 48798/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TTA_fuzzer-5409428670644224

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 2022-09-11 00:11:20 +02:00
parent 677e27a9af
commit 3993345f91
No known key found for this signature in database
GPG Key ID: B18E8928B3948D64
1 changed files with 9 additions and 2 deletions

View File

@ -377,8 +377,15 @@ static int tta_decode_frame(AVCodecContext *avctx, AVFrame *frame,
case 3: {
// shift samples for 24-bit sample format
int32_t *samples = (int32_t *)frame->data[0];
for (i = 0; i < framelen * s->channels; i++)
*samples++ *= 256;
int overflow = 0;
for (i = 0; i < framelen * s->channels; i++) {
int scaled = *samples * 256U;
overflow += (scaled >> 8 != *samples);
*samples++ = scaled;
}
if (overflow)
av_log(avctx, AV_LOG_WARNING, "%d overflows occurred on 24bit upscale\n", overflow);
// reset decode buffer
s->decode_buffer = NULL;
break;