From 95ff7088fe170eab38fe1ba48a69878f3b1b9511 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 13 Aug 2023 20:35:55 +0200 Subject: [PATCH] fix issue 701: MSAN: ISM3 decoding hits SEGV in setting output buffers to zero --- lib_dec/ivas_dec.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 044eebd1e6..eb8e13c65a 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -179,6 +179,19 @@ ivas_error ivas_dec( if ( st_ivas->bfi && st_ivas->ini_frame == 0 ) { +#ifdef FIX_264_AUDIO_CHANNELS_TO_HEAP + for ( n = 0; n < nchan_out; n++ ) + { + /* note: these are intra-frame heap memories */ + if ( ( st_ivas->p_output_f[n] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); + } + output[n] = st_ivas->p_output_f[n]; + p_output[n] = output[n]; + } +#endif + /* zero output when first frame(s) is lost */ for ( n = 0; n < nchan_out; n++ ) { @@ -1255,6 +1268,18 @@ ivas_error ivas_dec( st_ivas->last_ivas_format = st_ivas->ivas_format; #endif +#ifdef FIX_264_AUDIO_CHANNELS_TO_HEAP + /* in case first frame(s) was/were lost, deallocate output buffers */ + if ( st_ivas->bfi && st_ivas->ini_frame == 0 ) + { + for ( n = 0; n < nchan_out; n++ ) + { + free( st_ivas->p_output_f[n] ); + st_ivas->p_output_f[n] = NULL; + } + } +#endif + #ifdef DEBUG_MODE_INFO dbgwrite( &st_ivas->bfi, sizeof( int16_t ), 1, output_frame, "res/bfi" ); dbgwrite( &st_ivas->BER_detect, sizeof( int16_t ), 1, output_frame, "res/BER_detect" ); -- GitLab