Skip to content

[CLANG18] MSAN: use-of-uninitialized-value in lib_dec/hf_synth.c:470:9

Msan error with clang 18 when bitstream starts with SID frame for AMR-WB:

==73820==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55fc12a84a4e in hf_synth_amr_wb /ivas-codec/lib_dec/hf_synth.c:470:9
    #1 0x55fc1297df35 in amr_wb_dec /ivas-codec/lib_dec/amr_wb_dec.c:728:9
    #2 0x55fc126f37df in evs_dec_main /ivas-codec/lib_dec/lib_dec.c:4844:28
    #3 0x55fc126ed4ce in IVAS_DEC_GetSamplesDecoder /ivas-codec/lib_dec/lib_dec.c:1194:28
    #4 0x55fc126b7511 in decodeG192 /ivas-codec/apps/decoder.c:2601:32
    #5 0x55fc1268d565 in main /ivas-codec/apps/decoder.c:790:17
    #6 0x7fa0691481c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #7 0x7fa06914828a in __libc_start_main csu/../csu/libc-start.c:360:3
    #8 0x55fc125ec634 in _start (/ivas-codec/IVAS_dec+0x3a634) (BuildId: d89e96f14ef8f9a13b35660baff9610ab5cea068)

  Uninitialized value was stored to memory at
    #0 0x55fc12a84a47 in hf_synth_amr_wb /ivas-codec/lib_dec/hf_synth.c:470:197
    #1 0x55fc1297df35 in amr_wb_dec /ivas-codec/lib_dec/amr_wb_dec.c:728:9
    #2 0x55fc126f37df in evs_dec_main /ivas-codec/lib_dec/lib_dec.c:4844:28
    #3 0x55fc126ed4ce in IVAS_DEC_GetSamplesDecoder /ivas-codec/lib_dec/lib_dec.c:1194:28
    #4 0x55fc126b7511 in decodeG192 /ivas-codec/apps/decoder.c:2601:32
    #5 0x55fc1268d565 in main /ivas-codec/apps/decoder.c:790:17
    #6 0x7fa0691481c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #7 0x7fa06914828a in __libc_start_main csu/../csu/libc-start.c:360:3
    #8 0x55fc125ec634 in _start (/ivas-codec/IVAS_dec+0x3a634) (BuildId: d89e96f14ef8f9a13b35660baff9610ab5cea068)

  Uninitialized value was created by an allocation of 'HF_corr_gain' in the stack frame
    #0 0x55fc12a794b8 in hf_synth_amr_wb /ivas-codec/lib_dec/hf_synth.c:195:5

SUMMARY: MemorySanitizer: use-of-uninitialized-value /ivas-codec/lib_dec/hf_synth.c:470:9 in hf_synth_amr_wb

The problematic variable

    float HF_corr_gain[NB_SUBFR];

is only set and accessed when the bitrate is 23.85kbps:

    if ( core_brate == ACELP_23k85 )
    {
        for ( i = 0; i < NB_SUBFR; i++ )
        {
            HF_corr_gain[i] = 2 * HP_gain[hf_gain[i]];
        }
    }
    if ( core_brate == ACELP_23k85 )
    {
        ener = ( sum2_f( exc, L_SUBFR ) + 0.01f ) / 5;
        tmp = sum2_f( exc16k, L_SUBFR16k ) + 0.01f;
        scale = (float) sqrt( ener / tmp );

        for ( i = 0; i < L_SUBFR16k; i++ )
        {
            exc2385[i] = exc16k[i] * scale * HF_corr_gain;
        }
    }

Clang 18 is probably jsut stricter than clang 13 and already complains about passing it to the function. Initializing it to 1 should silence the error.