shithub: opus

Download patch

ref: 6fd0270621a652484d06fa9d2a1a06721cd13400
parent: aebb6fd624c8c2d60a023ab778426465ae7661b6
author: George de Vries <[email protected]>
date: Wed Dec 2 15:59:44 EST 2009

Fixing (read) array overrun for 1024-sample frames.

--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -42,10 +42,12 @@
 #include "mathops.h"
 #include "stack_alloc.h"
 
+#define E_MEANS_SIZE (5)
+
 #ifdef FIXED_POINT
-const celt_word16 eMeans[24] = {1920, -341, -512, -107, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+const celt_word16 eMeans[E_MEANS_SIZE] = {1920, -341, -512, -107, 43};
 #else
-const celt_word16 eMeans[24] = {7.5f, -1.33f, -2.f, -0.42f, 0.17f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
+const celt_word16 eMeans[E_MEANS_SIZE] = {7.5f, -1.33f, -2.f, -0.42f, 0.17f};
 #endif
 
 /* FIXME: Implement for stereo */
@@ -112,7 +114,7 @@
          celt_word16 q;   /* dB */
          celt_word16 x;   /* dB */
          celt_word16 f;   /* Q8 */
-         celt_word16 mean = MULT16_16_Q15(Q15ONE-coef,eMeans[i]);
+         celt_word16 mean =  (i < E_MEANS_SIZE) ? MULT16_16_Q15(Q15ONE-coef,eMeans[i]) : 0;
          x = eBands[i+c*m->nbEBands];
 #ifdef FIXED_POINT
          f = x-mean -MULT16_16_Q15(coef,oldEBands[i+c*m->nbEBands])-prev[c];
@@ -241,7 +243,7 @@
       do {
          int qi;
          celt_word16 q;
-         celt_word16 mean = MULT16_16_Q15(Q15ONE-coef,eMeans[i]);
+         celt_word16 mean =  (i < E_MEANS_SIZE) ? MULT16_16_Q15(Q15ONE-coef,eMeans[i]) : 0;
          /* If we didn't have enough bits to encode all the energy, just assume something safe.
             We allow slightly busting the budget here */
          if (ec_dec_tell(dec, 0) > budget)