From 94dfbd9e931a9886e3d54cdd7fa03f21801772dc Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Mon, 24 Jul 2023 09:11:26 +0200 Subject: [PATCH 1/2] [fix] issue 616: UBSAN division by zero error in MCT --- lib_com/options.h | 2 ++ lib_enc/ivas_mct_core_enc.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index b35772ecc1..886c8e5acb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -211,6 +211,8 @@ #define FIX_622_SILENCE_USAN_WARNING /* FhG: silenceusan warning in ifft code */ #define FIX_615_UBSAN_SPAR_TO_DIRAC /*Dlb : Fix for UBSAN issue 615*/ +#define FIX_616_DIV_ZERO_MCT /*FhG : Fix UBSAN division by zero error of issue 616*/ + /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index 0c98f82d05..2a048ed2ea 100755 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -143,8 +143,13 @@ static void AdjustChannelRatios( } for ( i = 3; i < nChannels; i++ ) { +#ifdef FIX_616_DIV_ZERO_MCT + cur_ratio = (float) chBitRatios[i] / ( sum_ratio + FLT_MIN ); + tar_ratio = (float) force_ch_bit_ratios[i] / ( sum_tar_ratio + FLT_MIN ); +#else cur_ratio = (float) chBitRatios[i] / sum_ratio; tar_ratio = (float) force_ch_bit_ratios[i] / sum_tar_ratio; +#endif tar_ratio = min( tar_ratio, cur_ratio ); chBitRatios[i] = (int16_t) ( tar_ratio * sum_tar_ratio ); @@ -196,7 +201,7 @@ void ivas_mct_core_enc( int16_t ch, ch_core, nSubframes, L_subframeTCX; int16_t i, cpe_id, n, nAvailBits; int16_t nCPE; - float *orig_spectrum[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ + float *orig_spectrum[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ float powerSpec[MCT_MAX_CHANNELS][L_FRAME48k]; float powerSpecMsInv_long[MCT_MAX_CHANNELS][L_FRAME48k]; /* MS inv power spectrum, also inverse MDST spectrum */ float *powerSpecMsInv[MCT_MAX_CHANNELS][2]; -- GitLab From b7934d3f35d75fd55a80d389087bdf7adeab5212 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Mon, 24 Jul 2023 09:48:34 +0200 Subject: [PATCH 2/2] clang format --- lib_enc/ivas_mct_core_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 lib_enc/ivas_mct_core_enc.c diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c old mode 100755 new mode 100644 index 2a048ed2ea..99eb1d9eb5 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -201,7 +201,7 @@ void ivas_mct_core_enc( int16_t ch, ch_core, nSubframes, L_subframeTCX; int16_t i, cpe_id, n, nAvailBits; int16_t nCPE; - float *orig_spectrum[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ + float *orig_spectrum[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ float powerSpec[MCT_MAX_CHANNELS][L_FRAME48k]; float powerSpecMsInv_long[MCT_MAX_CHANNELS][L_FRAME48k]; /* MS inv power spectrum, also inverse MDST spectrum */ float *powerSpecMsInv[MCT_MAX_CHANNELS][2]; -- GitLab