aacenc_tns: fix out-of-bounds array access
authorRostislav Pehlivanov <atomnuker@gmail.com>
Sat, 29 Aug 2015 18:21:35 +0000 (19:21 +0100)
committerRostislav Pehlivanov <atomnuker@gmail.com>
Sat, 29 Aug 2015 18:21:35 +0000 (19:21 +0100)
Since the coefficients are stepped up to order + 1 it was possible
that it went over TNS_MAX_ORDER. Also just return in case the only
coefficient is less than the threshold.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
libavcodec/aacenc_tns.c

index 0b22b67..a7433a8 100644 (file)
@@ -97,6 +97,10 @@ static void process_tns_coeffs(TemporalNoiseShaping *tns, double *coef_raw,
             break;
         }
     }
+    order = av_clip(order, 0, TNS_MAX_ORDER - 1);
+    *order_p = order;
+    if (!order)
+        return;
 
     /* Step up procedure, convert to LPC coeffs */
     out[0] = 1.0f;
@@ -109,7 +113,6 @@ static void process_tns_coeffs(TemporalNoiseShaping *tns, double *coef_raw,
         }
         out[i] = lpc[i-1];
     }
-    *order_p = order;
     memcpy(lpc, out, TNS_MAX_ORDER*sizeof(float));
 }