From 246f91b655d600c7a389e46b3fe0713a8009b76d Mon Sep 17 00:00:00 2001 From: Seth Madison Date: Mon, 26 Dec 2016 17:36:23 -0500 Subject: [PATCH 1/4] Fix a small memory leak in Ap4CommonEncryption --- Source/C++/Core/Ap4CommonEncryption.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/C++/Core/Ap4CommonEncryption.cpp b/Source/C++/Core/Ap4CommonEncryption.cpp index efd36567d..94acb39d0 100644 --- a/Source/C++/Core/Ap4CommonEncryption.cpp +++ b/Source/C++/Core/Ap4CommonEncryption.cpp @@ -1873,6 +1873,8 @@ class AP4_CencFragmentDecrypter : public AP4_Processor::FragmentHandler { m_SaizAtom(saiz_atom), m_SampleEncryptionAtom(sample_encryption_atom) {} + ~AP4_CencFragmentDecrypter() { delete m_SampleDecrypter; } + // methods virtual AP4_Result ProcessFragment(); virtual AP4_Result FinishFragment(); From 0d6493d03e913744054f9022d89c922df518168b Mon Sep 17 00:00:00 2001 From: Thane Frivold Date: Fri, 7 Apr 2017 16:21:12 -0700 Subject: [PATCH 2/4] Minor changes to support an additional ID3 stream. --- Source/C++/Core/Ap4Mpeg2Ts.cpp | 29 ++++++++++++++++++++++++++++- Source/C++/Core/Ap4Mpeg2Ts.h | 4 ++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Source/C++/Core/Ap4Mpeg2Ts.cpp b/Source/C++/Core/Ap4Mpeg2Ts.cpp index 58af427e8..e2f098b93 100644 --- a/Source/C++/Core/Ap4Mpeg2Ts.cpp +++ b/Source/C++/Core/Ap4Mpeg2Ts.cpp @@ -721,7 +721,8 @@ AP4_Mpeg2TsVideoSampleStream::WriteSample(AP4_Sample& sample, +---------------------------------------------------------------------*/ AP4_Mpeg2TsWriter::AP4_Mpeg2TsWriter(AP4_UI16 pmt_pid) : m_Audio(NULL), - m_Video(NULL) + m_Video(NULL), + m_Id3(NULL) { m_PAT = new Stream(0); m_PMT = new Stream(pmt_pid); @@ -736,6 +737,7 @@ AP4_Mpeg2TsWriter::~AP4_Mpeg2TsWriter() delete m_PMT; delete m_Audio; delete m_Video; + delete m_Id3; } /*---------------------------------------------------------------------- @@ -799,6 +801,10 @@ AP4_Mpeg2TsWriter::WritePMT(AP4_ByteStream& output) section_length += 5+m_Video->m_Descriptor.GetDataSize();; pcr_pid = m_Video->GetPID(); } + if (m_Id3) { + section_length += 5+m_Id3->m_Descriptor.GetDataSize(); + // Don't consider the ID3 stream for the PCR (Program Clock Reference) + } writer.Write(0, 8); // pointer writer.Write(2, 8); // table_id @@ -839,6 +845,17 @@ AP4_Mpeg2TsWriter::WritePMT(AP4_ByteStream& output) } } + if (m_Id3) { + writer.Write(m_Id3->m_StreamType, 8); // stream_type + writer.Write(0x7, 3); // reserved + writer.Write(m_Id3->GetPID(), 13); // elementary_PID + writer.Write(0xF, 4); // reserved + writer.Write(m_Id3->m_Descriptor.GetDataSize(), 12); // ES_info_length + for (unsigned int i=0; im_Descriptor.GetDataSize(); i++) { + writer.Write(m_Id3->m_Descriptor.GetData()[i], 8); + } + } + writer.Write(ComputeCRC(writer.GetData()+1, section_length-1), 32); // CRC output.Write(writer.GetData(), section_length+4); @@ -901,6 +918,16 @@ AP4_Mpeg2TsWriter::SetVideoStream(AP4_UI32 timescale, return AP4_SUCCESS; } +/*---------------------------------------------------------------------- +| AP4_Mpeg2TsWriter::AssignId3Stream ++---------------------------------------------------------------------*/ +AP4_Result +AP4_Mpeg2TsWriter::AssignId3Stream(SampleStream* stream) +{ + m_Id3 = stream; + return AP4_SUCCESS; +} + /*---------------------------------------------------------------------- | AP4_Mpeg2TsWriter::SampleStream::WriteSample +---------------------------------------------------------------------*/ diff --git a/Source/C++/Core/Ap4Mpeg2Ts.h b/Source/C++/Core/Ap4Mpeg2Ts.h index 523223545..083430881 100644 --- a/Source/C++/Core/Ap4Mpeg2Ts.h +++ b/Source/C++/Core/Ap4Mpeg2Ts.h @@ -156,12 +156,16 @@ class AP4_Mpeg2TsWriter AP4_UI16 pid = AP4_MPEG2_TS_DEFAULT_PID_VIDEO, const AP4_UI08* descriptor = NULL, AP4_Size descriptor_length = 0); + // Using 'Assign' instead of 'Set' since a stream object is not + // actually created like in SetAudioStream() or SetVideoStream() + AP4_Result AssignId3Stream(SampleStream* stream); private: Stream* m_PAT; Stream* m_PMT; SampleStream* m_Audio; SampleStream* m_Video; + SampleStream* m_Id3; }; #endif // _AP4_MPEG2_TS_H_ From e2b82c8a630e6468f82d680870c30b3da388f6b9 Mon Sep 17 00:00:00 2001 From: Satheesh Velmurugan Date: Wed, 31 Jul 2024 19:57:51 -0700 Subject: [PATCH 3/4] Fix SEGV in AdjustChunkOffsets() --- Source/C++/Core/Ap4TrakAtom.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/C++/Core/Ap4TrakAtom.cpp b/Source/C++/Core/Ap4TrakAtom.cpp index 62bbc39bf..adaddffcc 100644 --- a/Source/C++/Core/Ap4TrakAtom.cpp +++ b/Source/C++/Core/Ap4TrakAtom.cpp @@ -315,9 +315,11 @@ AP4_TrakAtom::AdjustChunkOffsets(AP4_SI64 delta) AP4_Atom* atom; if ((atom = FindChild("mdia/minf/stbl/stco")) != NULL) { AP4_StcoAtom* stco = AP4_DYNAMIC_CAST(AP4_StcoAtom, atom); + if (stco == NULL) return AP4_ERROR_INVALID_FORMAT; return stco->AdjustChunkOffsets((int)delta); } else if ((atom = FindChild("mdia/minf/stbl/co64")) != NULL) { AP4_Co64Atom* co64 = AP4_DYNAMIC_CAST(AP4_Co64Atom, atom); + if (co64 == NULL) return AP4_ERROR_INVALID_FORMAT; return co64->AdjustChunkOffsets(delta); } else { return AP4_ERROR_INVALID_STATE; From 69d60d4d8cec8736d67225408a8eb7e6e1563856 Mon Sep 17 00:00:00 2001 From: Satheesh Velmurugan Date: Tue, 6 Aug 2024 18:43:28 -0700 Subject: [PATCH 4/4] Fix SEGV in GetAuxInfoType() (#3) --- Source/C++/Core/Ap4CommonEncryption.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/C++/Core/Ap4CommonEncryption.cpp b/Source/C++/Core/Ap4CommonEncryption.cpp index fbc4d1ffc..fb1af5863 100644 --- a/Source/C++/Core/Ap4CommonEncryption.cpp +++ b/Source/C++/Core/Ap4CommonEncryption.cpp @@ -2794,12 +2794,12 @@ AP4_CencSampleInfoTable::Create(AP4_ProtectedSampleDescription* sample_descripti child = child->GetNext()) { if (child->GetData()->GetType() == AP4_ATOM_TYPE_SAIO) { saio = AP4_DYNAMIC_CAST(AP4_SaioAtom, child->GetData()); - if (saio->GetAuxInfoType() != 0 && saio->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) { + if (saio != NULL && saio->GetAuxInfoType() != 0 && saio->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) { saio = NULL; } } else if (child->GetData()->GetType() == AP4_ATOM_TYPE_SAIZ) { saiz = AP4_DYNAMIC_CAST(AP4_SaizAtom, child->GetData()); - if (saiz->GetAuxInfoType() != 0 && saiz->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) { + if (saiz != NULL && saiz->GetAuxInfoType() != 0 && saiz->GetAuxInfoType() != AP4_PROTECTION_SCHEME_TYPE_CENC) { saiz = NULL; } }