From 561090e2bc5e13593318859c85101484e4788759 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 13:19:49 +0100 Subject: [PATCH 1/6] use offset instead of pre-set pointer --- lib_com/options.h | 1 + lib_enc/tcx_ltp_enc_fx.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index ee8c6be3a..3c2cd73ad 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_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_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 012d6fa02..71ab78e64 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "stl.h" #include "cnst.h" #include "basop_util.h" @@ -292,7 +292,11 @@ static void tcx_ltp_pitch_search_ivas_fx( const Word16 check_border_case, Word16 *border_case ) { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + Word16 i, t, t0, t_offset, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; +#else Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; +#endif Word32 cor_max, cor[256], *pt_cor, temp; Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; @@ -417,9 +421,13 @@ static void tcx_ltp_pitch_search_ivas_fx( * Search fractional pitch with 1/4 subsample resolution. * search the fractions around t0 and choose the one which maximizes * the interpolated normalized correlation. - *-----------------------------------------------------------------*/ + *--------------FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH---------------------------------------------------*/ +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + t_offset = sub( L_INTERPOL1, t0_min ); +#else pt_cor = cor + sub( L_INTERPOL1, t0_min ); +#endif t0 = t1; move16(); @@ -437,16 +445,28 @@ static void tcx_ltp_pitch_search_ivas_fx( { fraction = 0; move16(); +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_max = interpolate_corr( &cor[t0 + t_offset], fraction, pitres ); +#else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); +#endif } ELSE /* Process negative fractions */ { t0 = sub( t0, 1 ); +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_max = interpolate_corr( &cor[t0 + t_offset], fraction, pitres ); +#else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); +#endif FOR( i = fraction + step; i < pitres; i += step ) { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + temp = interpolate_corr( &cor[t0 + t_offset], i, pitres ); +#else temp = interpolate_corr( &pt_cor[t0], i, pitres ); +#endif IF( GT_32( temp, cor_max ) ) { @@ -459,7 +479,11 @@ static void tcx_ltp_pitch_search_ivas_fx( FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + temp = interpolate_corr( &cor[t1 + t_offset], i, pitres ); +#else temp = interpolate_corr( &pt_cor[t1], i, pitres ); +#endif IF( GT_32( temp, cor_max ) ) { -- GitLab From 5a744a05e96b891f62ad9e10ad67f83053ea3bb1 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 14:45:09 +0100 Subject: [PATCH 2/6] cleanup fix for 2272 - rename variable - use BASOP for addition - move calculation out of loop --- lib_enc/tcx_ltp_enc_fx.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 71ab78e64..3b3923dd1 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -293,7 +293,7 @@ static void tcx_ltp_pitch_search_ivas_fx( Word16 *border_case ) { #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - Word16 i, t, t0, t_offset, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; + Word16 i, t, t0, cor_idx, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; #else Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; #endif @@ -423,7 +423,7 @@ static void tcx_ltp_pitch_search_ivas_fx( * the interpolated normalized correlation. *--------------FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH---------------------------------------------------*/ #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - t_offset = sub( L_INTERPOL1, t0_min ); + cor_idx = sub( L_INTERPOL1, t0_min ); #else pt_cor = cor + sub( L_INTERPOL1, t0_min ); @@ -443,19 +443,29 @@ static void tcx_ltp_pitch_search_ivas_fx( IF( EQ_16( t0, t0_min ) ) /* Limit case */ { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + Word16 cor_idx_tmp; + + cor_idx_tmp = add( cor_idx, t0 ); +#endif fraction = 0; move16(); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_max = interpolate_corr( &cor[t0 + t_offset], fraction, pitres ); + cor_max = interpolate_corr( &cor[cor_idx_tmp], 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 + Word16 cor_idx_tmp; + + cor_idx_tmp = add( cor_idx, t0 ); +#endif t0 = sub( t0, 1 ); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_max = interpolate_corr( &cor[t0 + t_offset], fraction, pitres ); + cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); #else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); #endif @@ -463,7 +473,7 @@ static void tcx_ltp_pitch_search_ivas_fx( FOR( i = fraction + step; i < pitres; i += step ) { #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - temp = interpolate_corr( &cor[t0 + t_offset], i, pitres ); + temp = interpolate_corr( &cor[cor_idx_tmp], i, pitres ); #else temp = interpolate_corr( &pt_cor[t0], i, pitres ); #endif @@ -477,10 +487,13 @@ static void tcx_ltp_pitch_search_ivas_fx( } } +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx = add( t1, cor_idx ); +#endif FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - temp = interpolate_corr( &cor[t1 + t_offset], i, pitres ); + temp = interpolate_corr( &cor[cor_idx], i, pitres ); #else temp = interpolate_corr( &pt_cor[t1], i, pitres ); #endif -- GitLab From 03d286d74d7e4b936a3a3a5a4db0da7fdea37f18 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 14:48:01 +0100 Subject: [PATCH 3/6] fix mistake --- lib_enc/tcx_ltp_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 3b3923dd1..f40ce2e80 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -421,7 +421,7 @@ static void tcx_ltp_pitch_search_ivas_fx( * Search fractional pitch with 1/4 subsample resolution. * search the fractions around t0 and choose the one which maximizes * the interpolated normalized correlation. - *--------------FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH---------------------------------------------------*/ + *-----------------------------------------------------------------*/ #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH cor_idx = sub( L_INTERPOL1, t0_min ); #else -- GitLab From cbef815487ff50eedff6f8195c20e0b49ecda8f3 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 15:22:48 +0100 Subject: [PATCH 4/6] apply fix also to EVS part of code fixes #2279, too --- lib_enc/tcx_ltp_enc_fx.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index f40ce2e80..5533af993 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -88,7 +88,11 @@ static void tcx_ltp_pitch_search( Word16 pitmax, Word16 pitres ) { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + Word16 i, t, t0, t1, cor_idx, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; +#else Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; +#endif Word32 cor_max, cor[256], *pt_cor, temp; Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; @@ -203,7 +207,11 @@ static void tcx_ltp_pitch_search( * the interpolated normalized correlation. *-----------------------------------------------------------------*/ +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx = sub( L_INTERPOL1, t0_min ); +#else pt_cor = cor + sub( L_INTERPOL1, t0_min ); +#endif t0 = t1; move16(); @@ -219,18 +227,40 @@ static void tcx_ltp_pitch_search( IF( EQ_16( t0, t0_min ) ) /* Limit case */ { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + Word16 cor_idx_tmp; + + cor_idx_tmp = add( cor_idx, t0 ); +#endif fraction = 0; move16(); +#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 } ELSE /* Process negative fractions */ { +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + Word16 cor_idx_tmp; + + cor_idx_tmp = add( cor_idx, t0 ); +#endif t0 = sub( t0, 1 ); +#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; 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( GT_32( temp, cor_max ) ) { @@ -241,11 +271,16 @@ static void tcx_ltp_pitch_search( } } - i = 0; - move16(); +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx = add( t1, cor_idx ); +#endif FOR( i = 0; i < pitres; 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( GT_32( temp, cor_max ) ) { -- GitLab From 0674e858fff69de64fbb7c04a712bfe2a8905c18 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 12 Dec 2025 15:26:21 +0100 Subject: [PATCH 5/6] fix index calculation - needs to be done after t0 update --- lib_enc/tcx_ltp_enc_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 5533af993..041bfcf2a 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -245,10 +245,10 @@ static void tcx_ltp_pitch_search( #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH Word16 cor_idx_tmp; - cor_idx_tmp = add( cor_idx, t0 ); #endif t0 = sub( t0, 1 ); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx_tmp = add( cor_idx, t0 ); cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); #else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); @@ -496,10 +496,10 @@ static void tcx_ltp_pitch_search_ivas_fx( #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH Word16 cor_idx_tmp; - cor_idx_tmp = add( cor_idx, t0 ); #endif t0 = sub( t0, 1 ); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + cor_idx_tmp = add( 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 7ef2e5d9d0f6cec6056edd59f3cc0829bc77ee55 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 12 Dec 2025 16:25:26 +0100 Subject: [PATCH 6/6] slight rework of patch --- lib_enc/tcx_ltp_enc_fx.c | 50 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 041bfcf2a..bd43b84f1 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -88,10 +88,9 @@ static void tcx_ltp_pitch_search( Word16 pitmax, Word16 pitres ) { -#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - Word16 i, t, t0, t1, cor_idx, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; -#else Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + Word16 cor_idx_ini, cor_idx; #endif Word32 cor_max, cor[256], *pt_cor, temp; Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; @@ -208,7 +207,7 @@ static void tcx_ltp_pitch_search( *-----------------------------------------------------------------*/ #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx = sub( L_INTERPOL1, t0_min ); + cor_idx_ini = sub( L_INTERPOL1, t0_min ); #else pt_cor = cor + sub( L_INTERPOL1, t0_min ); #endif @@ -228,28 +227,22 @@ static void tcx_ltp_pitch_search( IF( EQ_16( t0, t0_min ) ) /* Limit case */ { #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - Word16 cor_idx_tmp; - - cor_idx_tmp = add( cor_idx, t0 ); + cor_idx = add( cor_idx_ini, t0 ); #endif fraction = 0; move16(); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); + 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 - Word16 cor_idx_tmp; - -#endif t0 = sub( t0, 1 ); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx_tmp = add( cor_idx, t0 ); - cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); + cor_idx = add( cor_idx_ini, t0 ); + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); #else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); #endif @@ -257,7 +250,7 @@ static void tcx_ltp_pitch_search( FOR( i = fraction + step; i < pitres; 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 @@ -272,7 +265,7 @@ static void tcx_ltp_pitch_search( } #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx = add( t1, cor_idx ); + cor_idx = add( cor_idx_ini, t1 ); #endif FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { @@ -327,10 +320,9 @@ static void tcx_ltp_pitch_search_ivas_fx( const Word16 check_border_case, Word16 *border_case ) { -#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - Word16 i, t, t0, cor_idx, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; -#else Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; +#ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH + Word16 cor_idx_ini, cor_idx; #endif Word32 cor_max, cor[256], *pt_cor, temp; Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; @@ -458,7 +450,7 @@ static void tcx_ltp_pitch_search_ivas_fx( * the interpolated normalized correlation. *-----------------------------------------------------------------*/ #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx = sub( L_INTERPOL1, t0_min ); + cor_idx_ini = sub( L_INTERPOL1, t0_min ); #else pt_cor = cor + sub( L_INTERPOL1, t0_min ); @@ -479,28 +471,22 @@ static void tcx_ltp_pitch_search_ivas_fx( IF( EQ_16( t0, t0_min ) ) /* Limit case */ { #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - Word16 cor_idx_tmp; - - cor_idx_tmp = add( cor_idx, t0 ); + cor_idx = add( cor_idx_ini, t0 ); #endif fraction = 0; move16(); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); + 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 - Word16 cor_idx_tmp; - -#endif t0 = sub( t0, 1 ); #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx_tmp = add( cor_idx, t0 ); - cor_max = interpolate_corr( &cor[cor_idx_tmp], fraction, pitres ); + cor_idx = add( cor_idx_ini, t0 ); + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); #else cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); #endif @@ -508,7 +494,7 @@ static void tcx_ltp_pitch_search_ivas_fx( FOR( i = fraction + step; i < pitres; 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 @@ -523,7 +509,7 @@ static void tcx_ltp_pitch_search_ivas_fx( } #ifdef FIX_2272_OOB_INDEXING_IN_LTP_PIT_SEARCH - cor_idx = add( t1, cor_idx ); + cor_idx = add( cor_idx_ini, t1 ); #endif FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { -- GitLab