avcodec/ilbcdec: Limit indexes in create_augmented_vector()
authorMichael Niedermayer <michael@niedermayer.cc>
Wed, 10 Oct 2018 21:43:27 +0000 (23:43 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 18 Oct 2018 00:28:54 +0000 (02:28 +0200)
These limits are based on limiting done in WebRtcIlbcfix_CreateAugmentedVec()
Fixes: out of array accesses
Fixes: 10652/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ILBC_fuzzer-5638941487661056
Fixes: 10655/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ILBC_fuzzer-5699970020147200

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

index dc8f961..76ecdf0 100644 (file)
@@ -631,15 +631,16 @@ static void add_vector_and_shift(int16_t *out, const int16_t *in1,
 static void create_augmented_vector(int index, int16_t *buffer, int16_t *cbVec)
 {
     int16_t cbVecTmp[4];
-    int16_t ilow = index - 4;
+    int interpolation_length = FFMIN(4, index);
+    int16_t ilow = index - interpolation_length;
 
     memcpy(cbVec, buffer - index, index * 2);
 
-    vector_multiplication(&cbVec[ilow], buffer - index - 4, alpha, 4, 15);
-    vector_rmultiplication(cbVecTmp, buffer - 4, &alpha[3], 4, 15);
-    add_vector_and_shift(&cbVec[ilow], &cbVec[ilow], cbVecTmp, 4, 0);
+    vector_multiplication(&cbVec[ilow], buffer - index - interpolation_length, alpha, interpolation_length, 15);
+    vector_rmultiplication(cbVecTmp, buffer - interpolation_length, &alpha[interpolation_length - 1], interpolation_length, 15);
+    add_vector_and_shift(&cbVec[ilow], &cbVec[ilow], cbVecTmp, interpolation_length, 0);
 
-    memcpy(cbVec + index, buffer - index, (SUBL - index) * sizeof(*cbVec));
+    memcpy(cbVec + index, buffer - index, FFMIN(SUBL - index, index) * sizeof(*cbVec));
 }
 
 static void get_codebook(int16_t * cbvec,   /* (o) Constructed codebook vector */