diff --git a/Source/C++/Core/Ap4TrunAtom.cpp b/Source/C++/Core/Ap4TrunAtom.cpp index 6784ee7b..a3143cfb 100644 --- a/Source/C++/Core/Ap4TrunAtom.cpp +++ b/Source/C++/Core/Ap4TrunAtom.cpp @@ -37,6 +37,11 @@ +---------------------------------------------------------------------*/ AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_TrunAtom) +/*---------------------------------------------------------------------- +| constants ++---------------------------------------------------------------------*/ +#define AP4_TRUN_MAX_SAMPLE_COUNT 0xFFFFFF + /*---------------------------------------------------------------------- | AP4_TrunAtom::Create +---------------------------------------------------------------------*/ @@ -143,14 +148,15 @@ AP4_TrunAtom::AP4_TrunAtom(AP4_UI32 size, } int record_fields_count = (int)ComputeRecordFieldsCount(flags); - if (!record_fields_count) { - // nothing to read - return; - } - - if ((bytes_left / (record_fields_count*4)) < sample_count) { - // not enough data for all samples, the format is invalid - return; + if (record_fields_count) { + if ((bytes_left / (record_fields_count*4)) < sample_count) { + // not enough data for all samples, the format is invalid + return; + } + } else { + if (sample_count > AP4_TRUN_MAX_SAMPLE_COUNT) { + return; + } } if (AP4_FAILED(m_Entries.SetItemCount(sample_count))) {