UBSAN: index out of bounds in ivas_spar_calc_smooth_facs
When running
make clean
make -j CLANG=3
./IVAS_cod -SBA 3 ./scripts/switchPaths/sw_13k2_512k.bin 48 ./scripts/testv/stv3OA48c.wav bit
./IVAS_dec HOA3 48 bit out.wav
, UBSAN reports:
lib_dec/ivas_spar_decoder.c:1031:22: runtime error: index 60 out of bounds for type 'int16_t [60]'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib_dec/ivas_spar_decoder.c:1031:22 in
The problematic line is ivas_spar_decoder.c:1013:
while ( b == bin2band->p_cldfb_map_to_spar_band[bin] )
{
for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ )
{
subframe_band_nrg[b] += cldfb_in_ts_re[ts][bin] * cldfb_in_ts_re[ts][bin] + cldfb_in_ts_im[ts][bin] * cldfb_in_ts_im[ts][bin];
}
bin++;
}
This could theoretically change the calculation if the out-of-bounds dereference by chance fulfills the condition. Potential fix could be to change check to
while ( bin < CLDFB_NO_CHANNELS_MAX && b == bin2band->p_cldfb_map_to_spar_band[bin] )
or to change from while loop to do-while.