Commit 863b846c authored by Manuel Jander's avatar Manuel Jander
Browse files

Fix overflow crash in SWB_BWE_encoding_fx().

parent 1b99432d
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -88,7 +88,8 @@
#define NONBE_FIX_ISSUE_2206_TV1                        /* VA/FhG: Calculate st->q_inp also considering st->mem_q decimation memory to avoid saturation */
#define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT             /* FhG: Dynamic scale of shb_speech buffers */
// #define NONBE_FIX_ISSUE_2206_DO_NOT_FLUSH_TO_ZERO       /* FhG: Do not right shift flush to zero in Copy_Scale_sig_nosat */
#define NONBE_FIX_ISSUE_2206_TD_CHANNEL_EXTRAPOLATION   /* FhG: Use different scale to avoid saturation LPC coefficient in TD Stereo signal extrapolation. */
#define NONBE_FIX_ISSUE_2206_TD_CHANNEL_EXTRAPOLATION   /* FhG: Use different scale to avoid saturation of LPC coefficient in TD Stereo signal extrapolation. */
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_SWB_fenv_fx /* FhG: Avoid overflow of SWB_fenv_fx in SWB_BWE_encoding_fx because of very small energies. */
#define HARM_HQ_CORE_KEEP_BE                            /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */
#define FIX_2452_HQ_CORE_PEAQ_AVR_RATIO_HARM            /* Eri: Basop issue 2453: Fix alignment of peak_avrg_ratio_fx */
#define FIX_2480_HARM_TONALMDCT                         /* FhG: basop issue 2480: Harmonize TonalMDCTConceal_Detect_fx() and TonalMDCTConceal_Detect_ivas_fx() */
+38 −0
Original line number Diff line number Diff line
@@ -2630,6 +2630,43 @@ static Word16 SWB_BWE_encoding_fx(
            L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /* 2*Q_synth-5  / q_SWB_fenv[n_band] */
            L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] );     /* 2*Q_synth-5  / q_SWB_fenv[n_band] */

#ifdef NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_SWB_fenv_fx
            IF( st_fx->element_mode == EVS_MONO )
            {
                IF( L_tmp != 0 )
                {
                    expn = norm_l( L_tmp );
                    tmp = Log2_norm_lc( L_shl( L_tmp, expn ) );
                    expn = sub( 30, add( expn, sub( shl( Q_synth, 1 ), 5 ) ) );
                    L_tmp = Mpy_32_16( expn, tmp, 24660 ); /* Q14 */      /*10log10(2) in Q13 */
                    SWB_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */
                    move16();
                }
                ELSE
                {
                    SWB_fenv_fx[n_band] = -24576;
                    move16();
                }
            }
            ELSE
            {
                /* Limit small values to avoid overflow in sub( SWB_fenv_fx[n_band], Mean_env_fx[n_band] ) below. */
                IF ( LT_16( q_SWB_fenv[n_band], 58 ) )
                {
                    expn = norm_l( L_tmp );
                    tmp = Log2_norm_lc( L_shl( L_tmp, expn ) );
                    expn = sub( 30, add( expn, q_SWB_fenv[n_band] ) );
                    L_tmp = Mpy_32_16( expn, tmp, 24660 ); /* Q14 */      /*10log10(2) in Q13 */
                    SWB_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */
                    move16();
                }
                ELSE
                {
                    SWB_fenv_fx[n_band] = -24576;
                    move16();
                }
            }
#else
            IF( L_tmp != 0 )
            {
                expn = norm_l( L_tmp );
@@ -2651,6 +2688,7 @@ static Word16 SWB_BWE_encoding_fx(
                SWB_fenv_fx[n_band] = -24576;
                move16();
            }
#endif
        }
        freq_weights_fx( SWB_fenv_fx, w_NOR_fx, w_env_fx, SWB_FENV );