shithub: opus

Download patch

ref: 44ce46dc129f136c93da492299562c1f0fcd519d
parent: 2557750095863a1f038b85700a4131d3e29a7405
author: Koen Vos <[email protected]>
date: Fri Sep 23 09:05:22 EDT 2011

Fixes a decoder overflow on random input

Also some MSVC build fixes

--- a/silk/decode_core.c
+++ b/silk/decode_core.c
@@ -44,7 +44,7 @@
     opus_int   i, j, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType;
     opus_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];
     opus_int16 sLTP[ MAX_FRAME_LENGTH ];
-    opus_int32 LTP_pred_Q14, LPC_pred_Q10, Gain_Q16, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10;
+    opus_int32 LTP_pred_Q14, LPC_pred_Q10, Gain_Q10, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10;
     opus_int32 *pred_lag_ptr, *pexc_Q10, *pres_Q10;
     opus_int32 res_Q10[ MAX_SUB_FRAME_LENGTH ];
     opus_int32 vec_Q10[ MAX_SUB_FRAME_LENGTH ];
@@ -91,10 +91,10 @@
         /* Preload LPC coeficients to array on stack. Gives small performance gain */
         silk_memcpy( A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof( opus_int16 ) );
         B_Q14        = &psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER ];
-        Gain_Q16     = psDecCtrl->Gains_Q16[ k ];
+        Gain_Q10     = silk_RSHIFT( psDecCtrl->Gains_Q16[ k ], 6 );
         signalType   = psDec->indices.signalType;
 
-        inv_gain_Q16 = silk_INVERSE32_varQ( silk_max( Gain_Q16, 1 ), 32 );
+        inv_gain_Q16 = silk_INVERSE32_varQ( Gain_Q10, 26 );
         inv_gain_Q16 = silk_min( inv_gain_Q16, silk_int16_MAX );
 
         /* Calculate Gain adjustment factor */
@@ -209,7 +209,7 @@
 
         /* Scale with Gain */
         for( i = 0; i < psDec->subfr_length; i++ ) {
-            pxq[ i ] = ( opus_int16 )silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( vec_Q10[ i ], Gain_Q16 ), 10 ) );
+            pxq[ i ] = ( opus_int16 )silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( vec_Q10[ i ], Gain_Q10 ), 4 ) );
         }
 
         /* Update LPC filter state */
--- a/src/opus.vcxproj
+++ b/src/opus.vcxproj
@@ -83,16 +83,15 @@
     <ClCompile Include="opus.c" />
     <ClCompile Include="opus_decoder.c" />
     <ClCompile Include="opus_encoder.c" />
+    <ClCompile Include="repacketizer.c" />
     <ClCompile Include="test_opus.c" />
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="..\silk\silk_API.h" />
     <ClInclude Include="..\win32\config.h" />
     <ClInclude Include="opus.h" />
-    <ClInclude Include="opus_decoder.h" />
-    <ClInclude Include="opus_encoder.h" />
+    <ClInclude Include="opus_private.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
--- a/src/opus.vcxproj.filters
+++ b/src/opus.vcxproj.filters
@@ -27,14 +27,11 @@
     <ClCompile Include="opus.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="repacketizer.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="opus_decoder.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="opus_encoder.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="opus.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -41,7 +38,7 @@
     <ClInclude Include="..\win32\config.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\silk\silk_API.h">
+    <ClInclude Include="opus_private.h">
       <Filter>Header Files</Filter>
     </ClInclude>
   </ItemGroup>