avcodec/opus_silk: Fix integer overflow and out of array read
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 6 May 2017 12:28:20 +0000 (14:28 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 6 May 2017 12:29:12 +0000 (14:29 +0200)
Fixes: 1362/clusterfuzz-testcase-minimized-6097275002552320

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/opus_silk.c

index bfaf1d7..dbf6756 100644 (file)
@@ -128,8 +128,7 @@ static inline void silk_stabilize_lsf(int16_t nlsf[16], int order, const uint16_
     if (nlsf[0] < min_delta[0])
         nlsf[0] = min_delta[0];
     for (i = 1; i < order; i++)
-        if (nlsf[i] < nlsf[i - 1] + min_delta[i])
-            nlsf[i] = nlsf[i - 1] + min_delta[i];
+        nlsf[i] = FFMAX(nlsf[i], FFMIN(nlsf[i - 1] + min_delta[i], 32767));
 
     /* push backwards to increase distance */
     if (nlsf[order-1] > 32768 - min_delta[order])