1
0
mirror of https://git.ffmpeg.org/ffmpeg.git synced 2026-10-24 02:09:03 +03:00

avcodec/elbg: keep the total error in 64 bits

Signed integer overflow Replicated through Modified FFmpeg (fuzzer harness built with --disable-asm) with UBSAN

Fixes: signed integer overflow: 2147483647 - -106589 cannot be represented in type 'int'
Fixes: 472729757/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CINEPAK_fuzzer-5712538546536448
Fixes: fwDAxlQNlnpn
Regression since: ddc176d0ee

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
2026-10-10 18:05:42 +02:00
committed by michaelni
parent f603c70284
commit 17c71e3772

View File

@@ -45,7 +45,7 @@ typedef struct cell_s {
* ELBG internal data
*/
typedef struct ELBGContext {
int error;
int64_t error;
int dim;
int num_cb;
int *codebook;
@@ -368,9 +368,9 @@ static void do_elbg(ELBGContext *restrict elbg, int *points, int numpoints,
int *const size_part = elbg->size_part;
int i, j, steps = 0;
int best_idx = 0;
int last_error;
int64_t last_error;
elbg->error = INT_MAX;
elbg->error = INT64_MAX;
elbg->points = points;
do {
@@ -398,7 +398,7 @@ static void do_elbg(ELBGContext *restrict elbg, int *points, int numpoints,
}
}
elbg->nearest_cb[i] = best_idx;
elbg->error = (elbg->error >= INT_MAX - best_dist) ? INT_MAX : elbg->error + best_dist;
elbg->error += best_dist;
elbg->utility[elbg->nearest_cb[i]] = (elbg->utility[elbg->nearest_cb[i]] >= INT_MAX - best_dist) ?
INT_MAX : elbg->utility[elbg->nearest_cb[i]] + best_dist;
free_cells->index = i;