From 708ce19f26640d37537b0e09c6788cc1dd0f1cc6 Mon Sep 17 00:00:00 2001 From: Xingzhao Yun Date: Wed, 30 Oct 2024 14:48:06 +0800 Subject: [PATCH] fix dangling pointer for subtream object. --- Source/C++/Codecs/Ap4Ac4Parser.cpp | 8 +++++++- Source/C++/Core/Ap4Dac4Atom.cpp | 2 +- Source/C++/Core/Ap4Dac4Atom.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/C++/Codecs/Ap4Ac4Parser.cpp b/Source/C++/Codecs/Ap4Ac4Parser.cpp index 58f85a11..24a2892e 100644 --- a/Source/C++/Codecs/Ap4Ac4Parser.cpp +++ b/Source/C++/Codecs/Ap4Ac4Parser.cpp @@ -181,11 +181,17 @@ AP4_Ac4Header::AP4_Ac4Header(const AP4_UI08* bytes, unsigned int size) AP4_Ac4Header::~AP4_Ac4Header() { if (m_PresentationV1) { + bool removed_ss[32]; + AP4_SetMemory(removed_ss, false, sizeof(removed_ss)); assert(m_PresentationV1 != NULL); for (unsigned int pres_idx = 0; pres_idx < m_NPresentations; pres_idx++) { assert(m_PresentationV1[pres_idx].d.v1.substream_groups != NULL); for (int j = 0; j < m_PresentationV1[pres_idx].d.v1.n_substream_groups; j++) - delete[] m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams; + if (removed_ss[m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams->ss_idx]) break; + else{ + removed_ss[m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams->ss_idx] = true; + delete[] m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams; + } delete[] m_PresentationV1[pres_idx].d.v1.substream_groups; delete[] m_PresentationV1[pres_idx].d.v1.substream_group_indexs; } diff --git a/Source/C++/Core/Ap4Dac4Atom.cpp b/Source/C++/Core/Ap4Dac4Atom.cpp index 942f753b..07315f79 100644 --- a/Source/C++/Core/Ap4Dac4Atom.cpp +++ b/Source/C++/Core/Ap4Dac4Atom.cpp @@ -967,7 +967,7 @@ AP4_Dac4Atom::Ac4Dsi::SubStream::ParseSubstreamIdxInfo(AP4_BitReader &bits, unsi { if (b_substreams_present == 1) { if (bits.ReadBits(2) == 3) { // substream_index - AP4_Ac4VariableBits(bits, 2); + ss_idx = AP4_Ac4VariableBits(bits, 2); } } return AP4_SUCCESS; diff --git a/Source/C++/Core/Ap4Dac4Atom.h b/Source/C++/Core/Ap4Dac4Atom.h index 227c50a8..f39f6446 100644 --- a/Source/C++/Core/Ap4Dac4Atom.h +++ b/Source/C++/Core/Ap4Dac4Atom.h @@ -81,6 +81,7 @@ class AP4_Dac4Atom : public AP4_Atom AP4_UI08 b_substream_contains_bed_objects; AP4_UI08 b_substream_contains_dynamic_objects; AP4_UI08 b_substream_contains_ISF_objects; + AP4_UI08 ss_idx; // methods AP4_Result ParseSubstreamInfoChan(AP4_BitReader &bits,