From 97e307fb802c28295f6b8026125f2e1e323b0b2b Mon Sep 17 00:00:00 2001
From: Shashank Pathmudi <shashank.pathmudi@ittiam.com>
Date: Mon, 27 Nov 2023 12:23:49 +0530
Subject: [PATCH] Fix for write access violation and divide by zero in MPS
 module

---
 decoder/ixheaacd_aacdecoder.c | 6 ++++--
 decoder/ixheaacd_api.c        | 7 ++-----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/decoder/ixheaacd_aacdecoder.c b/decoder/ixheaacd_aacdecoder.c
index a5b958f..449c984 100644
--- a/decoder/ixheaacd_aacdecoder.c
+++ b/decoder/ixheaacd_aacdecoder.c
@@ -1120,8 +1120,10 @@ WORD32 ixheaacd_extension_payload(ia_bit_buf_struct *it_bit_buff, WORD32 *cnt,
       ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_type*/
       ixheaacd_read_bits_buf(it_bit_buff, 2);/*anc_start_stop*/
 
-      err = ixheaacd_ld_mps_frame_parsing(self, it_bit_buff);
-      if (err) return err;
+      if (self->ldmps_config.ldmps_present_flag == 1) {
+        err = ixheaacd_ld_mps_frame_parsing(self, it_bit_buff);
+        if (err) return err;
+      }
 
       *cnt = it_bit_buff->cnt_bits;
       break;
diff --git a/decoder/ixheaacd_api.c b/decoder/ixheaacd_api.c
index 9f60ef7..066bf9d 100644
--- a/decoder/ixheaacd_api.c
+++ b/decoder/ixheaacd_api.c
@@ -2452,11 +2452,8 @@ IA_ERRORCODE ixheaacd_dec_init(
              (p_obj_exhaacplus_dec->p_state_aac->audio_object_type ==
               AOT_ER_AAC_ELD)))
           p_obj_exhaacplus_dec->aac_config.flag_to_stereo = 1;
-        if (p_state_enhaacplus_dec->mps_dec_handle.ldmps_config
-                .ldmps_present_flag == 1) {
-          copy_qmf_to_ldmps(&p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle,
-                            p_state_enhaacplus_dec->sbr_persistent_mem_v);
-        }
+        copy_qmf_to_ldmps(&p_obj_exhaacplus_dec->p_state_aac->mps_dec_handle,
+                          p_state_enhaacplus_dec->sbr_persistent_mem_v);
         if (p_state_enhaacplus_dec->audio_object_type == AOT_AAC_LC &&
             p_state_enhaacplus_dec->ui_mps_out_bytes != 0) {
           p_state_enhaacplus_dec->heaac_mps_handle.heaac_mps_present = 1;