diff --git a/taglib/mp4/mp4qtchapterlist.cpp b/taglib/mp4/mp4qtchapterlist.cpp index 98572ce3..4dca59ed 100644 --- a/taglib/mp4/mp4qtchapterlist.cpp +++ b/taglib/mp4/mp4qtchapterlist.cpp @@ -943,19 +943,15 @@ namespace std::vector sampleOffsets; const auto totalChunks = static_cast(chunkOffsets.size()); unsigned int sampleIndex = 0; + std::size_t stscIndex = 0; for(unsigned int chunkIdx = 0; chunkIdx < totalChunks; ++chunkIdx) { // Find which stsc entry applies to this chunk (1-based) const unsigned int chunkNum = chunkIdx + 1; - unsigned int samplesInChunk = stscEntries[0].samplesPerChunk; - for(const auto & stscEntry : stscEntries) { - if(stscEntry.firstChunk <= chunkNum) { - samplesInChunk = stscEntry.samplesPerChunk; - } - else { - break; - } - } + while(stscIndex + 1 < stscEntries.size() && + stscEntries[stscIndex + 1].firstChunk <= chunkNum) + ++stscIndex; + unsigned int samplesInChunk = stscEntries[stscIndex].samplesPerChunk; unsigned int offsetInChunk = 0; if(samplesInChunk > sizeInfo.sampleCount - sampleIndex)