From 324c5710c9fd1e3aafc80398e06a611cf7c7c571 Mon Sep 17 00:00:00 2001 From: Gilles Boccon-Gibod Date: Sat, 3 Aug 2024 22:11:51 -0700 Subject: [PATCH] fix #975 --- Source/C++/Core/Ap4TrunAtom.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) 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))) {