Skip to content

Crash in stereo_icBWE_dec_fx() caused by a wrong equation implementation

in 6aad3441, there is a saturation in stereo_icBWE_dec_fx() causing a crash with the following bitstream (created with the floating point encoder):

stereo_sw_13k2_to_128k_10fr.bin_32.bit.zip

Once unzipped, the command line is: IVAS_DEC STEREO 32 stereo_sw_13k2_to_128k_10fr.bin_32.bit syn

The problem is located in ivas_stereo_icBWE_dec.c around line 1115 .

icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14

But the problem comes from a few line above where

the fixed point equivalent of "( 1 - ratio_L ) * ( 1 - ratio_L ) * gsMapping * gsMapping" is computed while in the else part of the it should rather be "ratio_L * ratio_L * gsMapping * gsMapping" (modification being delimitated by the switch FIX_TMP_714

            IF( GE_16( ratio_L_fx, 3276 ) )
            {
                tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15
                tmp = mult_r( tmp, gsMapping_fx );                                  // Q14
                tmp = mult_r( tmp, gsMapping_fx );                                  // Q13
                IF( LT_16( tmp, 4096 ) )
                {
                    temp1_fx = 0;
                    move16();
                    temp2_fx = 0;
                    move16();
                    tmp = shl( tmp, 2 );
                    icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx );
                    icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx );
                    icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14
                }
                ELSE
                {
                    icbweM2Ref_fx = 0;
                    move16();
                }
            }
        }
        ELSE
        {
            IF( LE_16( ratio_L_fx, 29490 ) )
            {
#ifdef FIX_TMP_714
                tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15
#else
                tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15
#endif
                tmp = mult_r( tmp, gsMapping_fx );                                  // Q14
                tmp = mult_r( tmp, gsMapping_fx );                                  // Q13
                IF( tmp < 4096 )
                {
                    temp1_fx = 0;
                    move16();
                    temp2_fx = 0;
                    move16();
                    tmp = shl( tmp, 2 );
                    icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx );
                    icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx );
                    icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14
                }
                ELSE
                {
                    icbweM2Ref_fx = 0;
                    move16();
                }

            }
        }


Edited by vaillancour