Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update m_sampleCount after successfully reading in m_Entries
This mostly reverts commit e6c7cda (except for the formatting).
  • Loading branch information
dimitry-ishenko committed May 12, 2021
1 parent 0c77057 commit f69a9c7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Source/C++/Core/Ap4StszAtom.cpp
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit f69a9c7

Please sign in to comment.