Skip to content

USAN: left shift of negative value for EVS decoding at 48kbps in waveadjust_fec_dec.c

Running

dly_profile.dat

make clean
make -j CLANG=3
UBSAN_OPTIONS=suppressions=scripts/ubsan.supp,report_error_type=1 ./IVAS_cod 48000 48 ltv48_MONO.wav bit
networkSimulator_g192 dly_profile.dat bit bit_err tracefile_sim 1
UBSAN_OPTIONS=suppressions=scripts/ubsan.supp,report_error_type=1 ./IVAS_dec -VOIP 48 bit_err out.wav

results in

lib_dec/waveadjust_fec_dec.c:745:55: runtime error: left shift of negative value -1
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib_dec/waveadjust_fec_dec.c:745:55 in 

See pipeline: https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/jobs/234373

Looking at the code, this seems to be intended:

void concealment_decode(
    const int16_t core,
    float *invkoef,
    T_PLCInfo_HANDLE hPlcInfo )
{
    int16_t i;
    int16_t *seed = &( hPlcInfo->seed );
    int16_t sign;

    if ( hPlcInfo->concealment_method == TCX_NONTONAL )
    {
        if ( core == TCX_20_CORE )
        {
            /* copy the data of the last frame */
            mvr2r( hPlcInfo->data_reci2, invkoef, hPlcInfo->L_frameTCX );

            /* sign randomization */
            for ( i = 0; i < hPlcInfo->L_frameTCX; i++ )
            {
                sign = ( ( own_random( seed ) >> 15 ) << 1 ) + 1;  // <---- Reported line
                invkoef[i] *= sign;
            }
        }
    }

    return;
}

From the C standard, right-shift of negative values is implementation-defined (thus not portable) and left-shift of negative values is undefined.

This is EVS-only code, so needs a CR if this should be fixed.