Skip to content

UBSAN: division by zero in stereo cng when inut is 16kHz and output is 32kHz

When running

make clean
make -j CLANG=3
./IVAS_cod -STEREO -dtx 24400 16 ./scripts/testv/stvST16nwav bit
./IVAS_dec stereo 32 bit out.wav

,UBSAN reports (among others):

lib_dec/ivas_stereo_cng_dec.c:380:29: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib_dec/ivas_stereo_cng_dec.c:380:29 in 
lib_dec/ivas_stereo_cng_dec.c:461:113: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib_dec/ivas_stereo_cng_dec.c:461:113 in 

This happens in frame 114. Running in the debugger and breaking at ivas_stereo_cng_dec.c:378, one can see that shb_shape is completely zero and thus the multiplication in line 380 has a zero denominator. The other division-by-zero error is a direct follow up of the first, as enr goes to Inf due to the division by zero.