From 0aa1645140e69a092150cd4e1c7e54321f6cfd12 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 29 Sep 2020 22:43:13 +0200 Subject: [PATCH] avcodec/mobiclip: Fix multiple integer overflows Fixes: signed integer overflow: 872415232 * 7 cannot be represented in type 'int' Fixes: signed integer overflow: -2013265888 + -1744830464 cannot be represented in type 'int' Fixes: 25834/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOBICLIP_fuzzer-5471406434025472 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/mobiclip.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index f890cb2599..0f150a551a 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -407,12 +407,12 @@ static int setup_qtables(AVCodecContext *avctx, int quantizer) return 0; } -static void inverse4(int *rs) +static void inverse4(unsigned *rs) { - int a = rs[0] + rs[2]; - int b = rs[0] - rs[2]; - int c = rs[1] + (rs[3] >> 1); - int d = (rs[1] >> 1) - rs[3]; + unsigned a = rs[0] + rs[2]; + unsigned b = rs[0] - rs[2]; + unsigned c = rs[1] + ((int)rs[3] >> 1); + unsigned d = ((int)rs[1] >> 1) - rs[3]; rs[0] = a + c; rs[1] = b + d; @@ -519,7 +519,7 @@ static int add_coefficients(AVCodecContext *avctx, AVFrame *frame, if (pos >= size * size) return AVERROR_INVALIDDATA; qval = qtab[pos]; - mat[ztab[pos]] = qval * level; + mat[ztab[pos]] = qval *(unsigned)level; if (last) break;