[FFmpeg-devel] [PATCH 1/4] avcodec/apedec: Fix multiple integer overflows in predictor_update_filter()

Michael Niedermayer michael at niedermayer.cc
Sun Jun 16 12:56:58 EEST 2019


Fixes: signed integer overflow: -829262115 + -1410750414 cannot be represented in type 'int'
Fixes: 15251/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-5651742252859392

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavcodec/apedec.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 15eb416ba4..2428c3cb64 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -1124,10 +1124,10 @@ static av_always_inline int predictor_update_filter(APEPredictor *p,
     p->buf[delayA - 1] = p->buf[delayA] - p->buf[delayA - 1];
     p->buf[adaptA - 1] = APESIGN(p->buf[delayA - 1]);
 
-    predictionA = p->buf[delayA    ] * p->coeffsA[filter][0] +
-                  p->buf[delayA - 1] * p->coeffsA[filter][1] +
-                  p->buf[delayA - 2] * p->coeffsA[filter][2] +
-                  p->buf[delayA - 3] * p->coeffsA[filter][3];
+    predictionA = p->buf[delayA    ] * (unsigned)p->coeffsA[filter][0] +
+                  p->buf[delayA - 1] * (unsigned)p->coeffsA[filter][1] +
+                  p->buf[delayA - 2] * (unsigned)p->coeffsA[filter][2] +
+                  p->buf[delayA - 3] * (unsigned)p->coeffsA[filter][3];
 
     /*  Apply a scaled first-order filter compression */
     p->buf[delayB]     = p->filterA[filter ^ 1] - ((p->filterB[filter] * 31) >> 5);
@@ -1136,13 +1136,13 @@ static av_always_inline int predictor_update_filter(APEPredictor *p,
     p->buf[adaptB - 1] = APESIGN(p->buf[delayB - 1]);
     p->filterB[filter] = p->filterA[filter ^ 1];
 
-    predictionB = p->buf[delayB    ] * p->coeffsB[filter][0] +
-                  p->buf[delayB - 1] * p->coeffsB[filter][1] +
-                  p->buf[delayB - 2] * p->coeffsB[filter][2] +
-                  p->buf[delayB - 3] * p->coeffsB[filter][3] +
-                  p->buf[delayB - 4] * p->coeffsB[filter][4];
+    predictionB = p->buf[delayB    ] * (unsigned)p->coeffsB[filter][0] +
+                  p->buf[delayB - 1] * (unsigned)p->coeffsB[filter][1] +
+                  p->buf[delayB - 2] * (unsigned)p->coeffsB[filter][2] +
+                  p->buf[delayB - 3] * (unsigned)p->coeffsB[filter][3] +
+                  p->buf[delayB - 4] * (unsigned)p->coeffsB[filter][4];
 
-    p->lastA[filter] = decoded + ((predictionA + (predictionB >> 1)) >> 10);
+    p->lastA[filter] = decoded + ((int)((unsigned)predictionA + (predictionB >> 1)) >> 10);
     p->filterA[filter] = p->lastA[filter] + ((p->filterA[filter] * 31) >> 5);
 
     sign = APESIGN(decoded);
-- 
2.21.0



More information about the ffmpeg-devel mailing list