From f3edea3a23241997faf48838c0aaefc68c6ac323 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Jul 2023 13:38:53 +0200 Subject: [PATCH 1/3] fix issue 618 - UBSAN: division-by-zero in stereo bitrate switching; under FIX_618_STEREO_SW_DIV_BY_ZERO --- lib_com/options.h | 2 ++ lib_enc/swb_tbe_enc.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index c2bc0b866b..318f5df710 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -209,6 +209,8 @@ #define FIX_615_UBSAN_SPAR_TO_DIRAC /*Dlb : Fix for UBSAN issue 615*/ #define FIX_626_VARIABLE_TYPE_MDCT_CONC /* FhG: trivial fix to fix USAN error */ #define FIX_616_DIV_ZERO_MCT /*FhG : Fix UBSAN division by zero error of issue 616*/ +#define FIX_618_STEREO_SW_DIV_BY_ZERO /* VA: fix issue 618 - UBSAN: division-by-zero in stereo bitrate switching */ + /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 38a0fb73ff..a57e381eb4 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -1259,7 +1259,11 @@ void swb_tbe_enc( GainFrame *= temp; } +#ifdef FIX_618_STEREO_SW_DIV_BY_ZERO + if ( st->element_mode > EVS_MONO && st->L_frame != st->last_L_frame && ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) && st->coder_type == TRANSITION && st->coder_type_raw != VOICED && st->clas == VOICED_CLAS && st->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st->L_frame >> 6 ) - 1] ) ) +#else if ( st->element_mode > EVS_MONO && st->L_frame != st->last_L_frame && st->coder_type == TRANSITION && st->coder_type_raw != VOICED && st->clas == VOICED_CLAS && st->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st->L_frame >> 6 ) - 1] ) ) +#endif { float fac = GainFrame / hBWE_TD->prev_gainFr_SHB; -- GitLab From 8f4cb001188b1f0919e4f5b4bea20fcdca468b5c Mon Sep 17 00:00:00 2001 From: malenovsky Date: Fri, 28 Jul 2023 11:19:07 +0000 Subject: [PATCH 2/3] Add condition mandating hBWE_TD->prev_gainFr_SHB != 0 --- lib_enc/swb_tbe_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index a57e381eb4..972a0b177d 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -1260,7 +1260,7 @@ void swb_tbe_enc( } #ifdef FIX_618_STEREO_SW_DIV_BY_ZERO - if ( st->element_mode > EVS_MONO && st->L_frame != st->last_L_frame && ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) && st->coder_type == TRANSITION && st->coder_type_raw != VOICED && st->clas == VOICED_CLAS && st->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st->L_frame >> 6 ) - 1] ) ) + if ( st->element_mode > EVS_MONO && st->L_frame != st->last_L_frame && hBWE_TD->prev_gainFr_SHB != 0 && ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) && st->coder_type == TRANSITION && st->coder_type_raw != VOICED && st->clas == VOICED_CLAS && st->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st->L_frame >> 6 ) - 1] ) ) #else if ( st->element_mode > EVS_MONO && st->L_frame != st->last_L_frame && st->coder_type == TRANSITION && st->coder_type_raw != VOICED && st->clas == VOICED_CLAS && st->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st->L_frame >> 6 ) - 1] ) ) #endif -- GitLab From 4599611975cd0978ca5e977078c1710d136fd433 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 28 Jul 2023 14:45:55 +0200 Subject: [PATCH 3/3] remove corresponding entry from ubsan.supp --- scripts/ubsan.supp | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/ubsan.supp b/scripts/ubsan.supp index 8f312aa15a..f0d062d29e 100644 --- a/scripts/ubsan.supp +++ b/scripts/ubsan.supp @@ -8,7 +8,6 @@ bounds:trans_direct.c bounds:trans_inv.c float-cast-overflow:ivas_dirac_com.c float-divide-by-zero:ivas_stereo_cng_dec.c -float-divide-by-zero:swb_tbe_enc.c implicit-integer-sign-change:ACcontextMapping.c implicit-integer-sign-change:avq_dec.c implicit-integer-sign-change:bitstream.c -- GitLab