[FFmpeg-cvslog] avcodec/mobiclip: Avoid signed integer overflows in idct()

Michael Niedermayer git at videolan.org
Tue Oct 20 17:28:02 EEST 2020


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Fri Oct 16 17:55:26 2020 +0200| [a4895b75a3030d624fd15793e830543b94a0f29c] | committer: Michael Niedermayer

avcodec/mobiclip: Avoid signed integer overflows in idct()

Fixes: signed integer overflow: 536870912 + 1610612736 cannot be represented in type 'int'
Fixes: 26288/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOBICLIP_fuzzer-6194364759670784

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a4895b75a3030d624fd15793e830543b94a0f29c
---

 libavcodec/mobiclip.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c
index 82ff39e958..48467614ab 100644
--- a/libavcodec/mobiclip.c
+++ b/libavcodec/mobiclip.c
@@ -422,7 +422,8 @@ static void inverse4(unsigned *rs)
 
 static void idct(int *arr, int size)
 {
-    int e, f, g, h, x3, x2, x1, x0;
+    int e, f, g, h;
+    unsigned x3, x2, x1, x0;
     int tmp[4];
 
     if (size == 4) {
@@ -437,14 +438,14 @@ static void idct(int *arr, int size)
 
     inverse4(tmp);
 
-    e = arr[7] + arr[1] - arr[3] - (arr[3] >> 1);
-    f = arr[7] - arr[1] + arr[5] + (arr[5] >> 1);
-    g = arr[5] - arr[3] - arr[7] - (arr[7] >> 1);
-    h = arr[5] + arr[3] + arr[1] + (arr[1] >> 1);
-    x3 = g + (h >> 2);
-    x2 = e + (f >> 2);
-    x1 = (e >> 2) - f;
-    x0 = h - (g >> 2);
+    e = (unsigned)arr[7] + arr[1] - arr[3] - (arr[3] >> 1);
+    f = (unsigned)arr[7] - arr[1] + arr[5] + (arr[5] >> 1);
+    g = (unsigned)arr[5] - arr[3] - arr[7] - (arr[7] >> 1);
+    h = (unsigned)arr[5] + arr[3] + arr[1] + (arr[1] >> 1);
+    x3 = (unsigned)g + (h >> 2);
+    x2 = (unsigned)e + (f >> 2);
+    x1 = (e >> 2) - (unsigned)f;
+    x0 = (unsigned)h - (g >> 2);
 
     arr[0] = tmp[0] + x0;
     arr[1] = tmp[1] + x1;



More information about the ffmpeg-cvslog mailing list