From 16a50ea91b2428fe90bb6b238b789d29caf27b50 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Thu, 9 Jan 2025 15:06:17 +0100 Subject: [PATCH] JBM: Limit max scaling to the duration of one frame This fixes integer overflows in max scaling calculation --- lib_com/options.h | 1 + lib_dec/jbm_jb4sb.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 23f991793e..96a76cb0fa 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -175,6 +175,7 @@ #define NONBE_1246_INF_COHERENCE_IN_HIGH_LEVEL_DTX /* Ericsson: Issue 1246: High level input which triggers DTX can lead to numerical overflow in coherence calculation */ #define NONBE_1211_DTX_BR_SWITCHING /* VA: issue 1211: fix crash in MASA DTX bitrate switching */ #define NONBE_1217_INIT_OBJ_EDIT /* VA: issue 1217: do object editing only when objects metadata is available */ +#define NONBE_1215_FIX_JBM_MAX_SCALING /* FhG: issue 1215: Fix assert hit in a specific VoIP decoder config. Caused by integer overflow in max scaling calculation. */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 8ea0e54d82..8b8f467d38 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -811,7 +811,15 @@ static void JB4_adaptActivePlayout( ( dropRateMax - dropRateMin ) / dropGapMax + dropRateMin; *scale = ( 1000 - rate ) / 10; +#ifdef NONBE_1215_FIX_JBM_MAX_SCALING + /* Limit max scaling to the duration of one frame. APA will not exceed this limit + * anyway due to the 50% limitation of APA_MIN_SCALE and APA_MAX_SCALE. Limiting + * the value to a sensible range here avoids integer overflows at later stages when + * converting maxScaling from milliseconds to samples. */ + *maxScaling = JB4_MIN( currPlayoutDelay - targetMax, 1000 / IVAS_NUM_FRAMES_PER_SEC ); +#else *maxScaling = currPlayoutDelay - targetMax; +#endif } } } @@ -827,7 +835,15 @@ static void JB4_adaptActivePlayout( currPlayoutDelay < targetMaxStretch && currPlayoutDelay < (uint32_t) ( 110 + h->rfDelay / 4 ) ) { *scale = 120; +#ifdef NONBE_1215_FIX_JBM_MAX_SCALING + /* Limit max scaling to the duration of one frame. APA will not exceed this limit + * anyway due to the 50% limitation of APA_MIN_SCALE and APA_MAX_SCALE. Limiting + * the value to a sensible range here avoids integer overflows at later stages when + * converting maxScaling from milliseconds to samples. */ + *maxScaling = JB4_MIN( targetMaxStretch - currPlayoutDelay, 1000 / IVAS_NUM_FRAMES_PER_SEC ); +#else *maxScaling = targetMaxStretch - currPlayoutDelay; +#endif } } -- GitLab