UBSAN: division-by-zero in stereo bitrate switching
When running
make
make -j CLANG=3
./IVAS_cod -stereo scripts/switchPaths/sw_13k2_to_128k_10fr.bin 32 scripts/testv/stvST32c.wav bit
, UBSAN reports (among others):
lib_enc/swb_tbe_enc.c:1264:31: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib_enc/swb_tbe_enc.c:1264:31 in
This happens in frame 390, which has a switch from 64000 kbps to 13200 kbps. The problem is that in swb_tbe_enc.c:1264
, hBWE_TD->prev_gainFr_SHB
is zero. This results in GainFrame
being 0 after this if block:
if ( st->element_mode > EVS_MONO && st->L_frame != st->last_L_frame && st->coder_type == TRANSITION && st->coder_type_raw != VOICED && st->clas == VOICED_CLAS && st->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st->L_frame >> 6 ) - 1] ) )
{
float fac = GainFrame / hBWE_TD->prev_gainFr_SHB;
if ( fac > 4.0f )
{
GainFrame = 4.0f * GainFrame / fac;
}
}
This is at least a sensible value, so nothing seems to break here. This could be caught and GainFrame
set explicitly (this would be the BE option). I don't know if this is also run in EVS path.