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

Submitted by Michael Niedermayer on June 16, 2019, 9:56 a.m.

Details

Message ID 20190616095701.31384-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer June 16, 2019, 9:56 a.m.
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@niedermayer.cc>
---
 libavcodec/apedec.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Michael Niedermayer July 21, 2019, 8:52 a.m.
On Sun, Jun 16, 2019 at 11:56:58AM +0200, Michael Niedermayer wrote:
> 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@niedermayer.cc>
> ---
>  libavcodec/apedec.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)

will apply

[...]

Patch hide | download patch | download mbox

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);