From 0aa505b38a55c1e9e91681a62f6fed936b206a04 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 15:14:22 +0100 Subject: [PATCH 1/3] use offset instead of pre-set pointer --- lib_com/options.h | 1 + lib_enc/tcx_ltp_enc.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 59daf40a86..33f6601f32 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ +#define FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH /* FhG: fix OOB index USAN error in TCX LTP pitch search */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/tcx_ltp_enc.c b/lib_enc/tcx_ltp_enc.c index c806d1b810..f25eb697ff 100644 --- a/lib_enc/tcx_ltp_enc.c +++ b/lib_enc/tcx_ltp_enc.c @@ -34,6 +34,7 @@ EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 ====================================================================================*/ +#include "cnst.h" #include #include "options.h" #ifdef DEBUGGING @@ -112,7 +113,11 @@ static void tcx_ltp_pitch_search( const int16_t check_border_case, int16_t *border_case ) { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + int16_t i, t, t0, cor_idx, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta; +#else int16_t i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta; +#endif float temp, cor_max, cor[256], *pt_cor; if ( pitres == 6 ) @@ -195,7 +200,11 @@ static void tcx_ltp_pitch_search( * the interpolated normalized correlation. *-----------------------------------------------------------------*/ +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx = L_INTERPOL1 - t0_min; +#else pt_cor = cor + L_INTERPOL1 - t0_min; +#endif t0 = t1; if ( t0 >= pitfr2 ) { @@ -211,15 +220,32 @@ static void tcx_ltp_pitch_search( if ( t0 == t0_min ) /* Limit case */ { fraction = 0; +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_max = interpolate_corr( &cor[cor_idx + t0], fraction, pitres ); +#else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); +#endif } else /* Process negative fractions */ { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + int16_t cor_idx_tmp; + + cor_idx_tmp = cor_idx + t0; +#endif t0--; +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); +#else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); +#endif for ( i = ( fraction + step ); i <= pitres - 1; i = i + step ) { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + temp = interpolate_corr( &cor[cor_idx_tmp], i, pitres ); +#else temp = interpolate_corr( &pt_cor[t0], i, pitres ); +#endif if ( temp > cor_max ) { cor_max = temp; @@ -228,9 +254,16 @@ static void tcx_ltp_pitch_search( } } +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx = t1 + cor_idx; +#endif for ( i = 0; i <= pitres - 1; i = i + step ) /* Process positive fractions */ { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + temp = interpolate_corr( &cor[cor_idx], i, pitres ); +#else temp = interpolate_corr( &pt_cor[t1], i, pitres ); +#endif if ( temp > cor_max ) { cor_max = temp; -- GitLab From 81a66211c8f6a98bea8496c1f80fc38107e6f532 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 15:30:02 +0100 Subject: [PATCH 2/3] fix index calculation --- lib_enc/tcx_ltp_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/tcx_ltp_enc.c b/lib_enc/tcx_ltp_enc.c index f25eb697ff..16d6722eb9 100644 --- a/lib_enc/tcx_ltp_enc.c +++ b/lib_enc/tcx_ltp_enc.c @@ -231,10 +231,10 @@ static void tcx_ltp_pitch_search( #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH int16_t cor_idx_tmp; - cor_idx_tmp = cor_idx + t0; #endif t0--; #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx_tmp = cor_idx + t0; cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); #else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); -- GitLab From cc8aa421008afb54cb623572bdab1271a2423d1e Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 12 Dec 2025 16:10:00 +0100 Subject: [PATCH 3/3] slight rework of patch --- lib_enc/tcx_ltp_enc.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib_enc/tcx_ltp_enc.c b/lib_enc/tcx_ltp_enc.c index 16d6722eb9..5e6ecbf4f8 100644 --- a/lib_enc/tcx_ltp_enc.c +++ b/lib_enc/tcx_ltp_enc.c @@ -113,10 +113,9 @@ static void tcx_ltp_pitch_search( const int16_t check_border_case, int16_t *border_case ) { -#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - int16_t i, t, t0, cor_idx, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta; -#else int16_t i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta; +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + int16_t cor_idx_ini, cor_idx; #endif float temp, cor_max, cor[256], *pt_cor; @@ -201,7 +200,7 @@ static void tcx_ltp_pitch_search( *-----------------------------------------------------------------*/ #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx = L_INTERPOL1 - t0_min; + cor_idx_ini = L_INTERPOL1 - t0_min; #else pt_cor = cor + L_INTERPOL1 - t0_min; #endif @@ -221,28 +220,25 @@ static void tcx_ltp_pitch_search( { fraction = 0; #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_max = interpolate_corr( &cor[cor_idx + t0], fraction, pitres ); + cor_idx = cor_idx_ini + t0; + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); #else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); #endif } else /* Process negative fractions */ { -#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - int16_t cor_idx_tmp; - -#endif t0--; #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx_tmp = cor_idx + t0; - cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); + cor_idx = cor_idx_ini + t0; + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); #else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); #endif for ( i = ( fraction + step ); i <= pitres - 1; i = i + step ) { #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - temp = interpolate_corr( &cor[cor_idx_tmp], i, pitres ); + temp = interpolate_corr( &cor[cor_idx], i, pitres ); #else temp = interpolate_corr( &pt_cor[t0], i, pitres ); #endif @@ -255,7 +251,7 @@ static void tcx_ltp_pitch_search( } #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx = t1 + cor_idx; + cor_idx = cor_idx_ini + t1; #endif for ( i = 0; i <= pitres - 1; i = i + step ) /* Process positive fractions */ { -- GitLab