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

avcodec/osq: Fix signed integer overflow in update_stats()

Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
Fixes: 410109093/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-6550900028276736

Note, none of the available osq files uses update_stats(), this change may fix or break
files using coding_mode == 2. The code prior looks wrong though

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-06-17 01:05:54 +02:00
parent 983a3b17e4
commit c909ef31be

View File

@ -146,8 +146,8 @@ static void reset_stats(OSQChannel *cb)
static void update_stats(OSQChannel *cb, int val) static void update_stats(OSQChannel *cb, int val)
{ {
cb->sum += FFABS(val) - cb->history[cb->pos]; cb->sum += FFABS((int64_t)val) - cb->history[cb->pos];
cb->history[cb->pos] = FFABS(val); cb->history[cb->pos] = FFABS((int64_t)val);
cb->pos++; cb->pos++;
cb->count++; cb->count++;
if (cb->pos >= FF_ARRAY_ELEMS(cb->history)) if (cb->pos >= FF_ARRAY_ELEMS(cb->history))