From 10c488dd3cff719870beca1b4b3898e48aa75fbe Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 17:13:52 +0100 Subject: [PATCH 1/3] avoid OOB indexing in pitch search --- lib_com/options.h | 1 + lib_enc/enc_gain_fx.c | 49 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index ee8c6be3a..fa0eefbbe 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -89,6 +89,7 @@ #define FIX_2252_SCALING_SAVE_HB_SYNTH /* VA: issue 2252: fix use-of-uninit-value in save_hb_synth_fx[] scaling in FOA decoding with bitstream that starts with an SID */ #define FIX_2248_EVS_ASSERT /* VA: Include _sat in an EVS related part of the code */ #define FIX_2254_IMPROV_COMPLEXITY_BE /* VA: BE small complexity reduction */ +#define FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH /* FhG: fix oob indexing USAN complaint */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/enc_gain_fx.c b/lib_enc/enc_gain_fx.c index 8c53a5d12..3ef9a029f 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -2,6 +2,7 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ +#include "basop32.h" #include #include #include "options.h" @@ -253,7 +254,11 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ { Word16 corr_v[32 + 2 * L_INTERPOL1 + 1]; Word16 cor_max, max, temp; +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + Word16 corr_idx; +#else Word16 *corr; +#endif Word16 i, fraction, frac1, frac2, step; Word16 t0, t_min, t_max; @@ -269,27 +274,48 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ move16(); move16(); +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + corr_idx = negate( t_min ); +#else /* allocate memory to normalized correlation vector */ corr = &corr_v[negate( t_min )]; /* corr[t_min..t_max] */ +#endif /* Compute normalized correlation between target and filtered excitation */ E_GAIN_norm_corr_fx( exc, xn, h, t_min, t_max, corr_v, L_subfr ); /* find integer pitch */ +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + max = corr_v[add( t0_min, corr_idx )]; /*(Q15+(Q_new+shift-1)+scale)*/ +#else max = corr[t0_min]; /*(Q15+(Q_new+shift-1)+scale)*/ +#endif move16(); t0 = t0_min; /*Q0*/ move16(); FOR( i = t0_min + 1; i <= t0_max; i++ ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + Word16 corr_tmp; + + corr_tmp = corr_v[add( corr_idx, i )]; +#endif BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + if ( GE_16( corr_tmp, max ) ) +#else if ( GE_16( corr[i], max ) ) +#endif { t0 = i; move16(); } +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + max = s_max( max, corr_tmp ); +#else max = s_max( max, corr[i] ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -354,15 +380,26 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ } assert( frac1 <= 0 && frac2 >= 0 && frac2 > frac1 ); +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + corr_idx = add( corr_idx, t0 ); +#endif IF( EQ_16( pit_res_max, 6 ) ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + cor_max = E_GAIN_norm_corr_interpolate6_fx( &corr_v[corr_idx], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ +#else cor_max = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ - fraction = frac1; /*Q0*/ +#endif + fraction = frac1; /*Q0*/ move16(); FOR( i = ( frac1 + step ); i <= frac2; i += step ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + temp = E_GAIN_norm_corr_interpolate6_fx( &corr_v[corr_idx], i ); /*(Q15+(Q_new+shift-1)+scale)*/ +#else temp = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ +#endif IF( GT_16( temp, cor_max ) ) { cor_max = temp; /*(Q15+(Q_new+shift-1)+scale)*/ @@ -374,13 +411,21 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ } ELSE { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + cor_max = E_GAIN_norm_corr_interpolate_fx( &corr_v[corr_idx], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ +#else cor_max = E_GAIN_norm_corr_interpolate_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ - fraction = frac1; /*Q0*/ +#endif + fraction = frac1; /*Q0*/ move16(); FOR( i = ( frac1 + step ); i <= frac2; i += step ) { +#ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH + temp = E_GAIN_norm_corr_interpolate_fx( &corr_v[corr_idx], i ); /*(Q15+(Q_new+shift-1)+scale)*/ +#else temp = E_GAIN_norm_corr_interpolate_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ +#endif IF( GT_16( temp, cor_max ) ) { cor_max = temp; /*(Q15+(Q_new+shift-1)+scale)*/ -- GitLab From ae84432a2c561b0e18c8b96e9af4a87573d40644 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Mon, 15 Dec 2025 12:12:23 +0100 Subject: [PATCH 2/3] apply clang-format --- lib_enc/enc_gain_fx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_enc/enc_gain_fx.c b/lib_enc/enc_gain_fx.c index 3ef9a029f..a1e47b455 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -288,7 +288,7 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ #ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH max = corr_v[add( t0_min, corr_idx )]; /*(Q15+(Q_new+shift-1)+scale)*/ #else - max = corr[t0_min]; /*(Q15+(Q_new+shift-1)+scale)*/ + max = corr[t0_min]; /*(Q15+(Q_new+shift-1)+scale)*/ #endif move16(); t0 = t0_min; /*Q0*/ @@ -398,7 +398,7 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ #ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH temp = E_GAIN_norm_corr_interpolate6_fx( &corr_v[corr_idx], i ); /*(Q15+(Q_new+shift-1)+scale)*/ #else - temp = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ + temp = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ #endif IF( GT_16( temp, cor_max ) ) { @@ -414,7 +414,7 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ #ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH cor_max = E_GAIN_norm_corr_interpolate_fx( &corr_v[corr_idx], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ #else - cor_max = E_GAIN_norm_corr_interpolate_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ + cor_max = E_GAIN_norm_corr_interpolate_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ #endif fraction = frac1; /*Q0*/ move16(); @@ -424,7 +424,7 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ #ifdef FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH temp = E_GAIN_norm_corr_interpolate_fx( &corr_v[corr_idx], i ); /*(Q15+(Q_new+shift-1)+scale)*/ #else - temp = E_GAIN_norm_corr_interpolate_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ + temp = E_GAIN_norm_corr_interpolate_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ #endif IF( GT_16( temp, cor_max ) ) { -- GitLab From 5d41cc2dde743d28c5e3c8c6c6621779b2d04b96 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Mon, 15 Dec 2025 13:46:55 +0100 Subject: [PATCH 3/3] replace include of basop32.h by stl.h --- lib_enc/enc_gain_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/enc_gain_fx.c b/lib_enc/enc_gain_fx.c index a1e47b455..ed954ebed 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ -#include "basop32.h" #include #include #include "options.h" +#include "stl.h" #include "cnst.h" #include "rom_com.h" #include "rom_enc.h" -- GitLab