diff --git a/Source/C++/Core/Ap4StszAtom.cpp b/Source/C++/Core/Ap4StszAtom.cpp index e3896e90..225dbbbd 100644 --- a/Source/C++/Core/Ap4StszAtom.cpp +++ b/Source/C++/Core/Ap4StszAtom.cpp @@ -78,25 +78,27 @@ AP4_StszAtom::AP4_StszAtom(AP4_UI32 size, } stream.ReadUI32(m_SampleSize); - stream.ReadUI32(m_SampleCount); + AP4_UI32 sampleCount; + stream.ReadUI32(sampleCount); if (m_SampleSize == 0) { // means that the samples have different sizes // check for overflow - if (m_SampleCount > (size - AP4_FULL_ATOM_HEADER_SIZE - 8) / 4) { + if (sampleCount > (size - AP4_FULL_ATOM_HEADER_SIZE - 8) / 4) { return; } // read the entries - unsigned char* buffer = new unsigned char[m_SampleCount * 4]; - AP4_Result result = stream.Read(buffer, m_SampleCount * 4); + unsigned char* buffer = new unsigned char[sampleCount * 4]; + AP4_Result result = stream.Read(buffer, sampleCount * 4); if (AP4_FAILED(result)) { delete[] buffer; return; } - m_Entries.SetItemCount((AP4_Cardinal)m_SampleCount); - for (unsigned int i = 0; i < m_SampleCount; i++) { + m_Entries.SetItemCount((AP4_Cardinal)sampleCount); + for (unsigned int i = 0; i < sampleCount; i++) { m_Entries[i] = AP4_BytesToUInt32BE(&buffer[i * 4]); } delete[] buffer; + m_SampleCount = sampleCount; } }