MP4: Fix QT chapters excessive sample allocation with invalid stsc (#1379)

See https://mail.kde.org/pipermail/taglib-devel/2026-July/003122.html

---------

Co-authored-by: Lee, Brian J <hibrian827@gatech.edu>
This commit is contained in:
Urs Fleisch
2026-07-17 05:22:50 +02:00
committed by GitHub
parent 93ebb7fb79
commit f7c28ac742

View File

@@ -825,6 +825,9 @@ namespace
const std::vector<unsigned int> chunkOffsets = readStco(file, chapterTrak);
if(chunkOffsets.empty())
return {};
// Sample count cannot be > file length / 4 as every sample consumes 4 bytes in stsz
if(sizeInfo.sampleCount == 0 || sizeInfo.sampleCount > file->length() / 4)
return {};
// Read stsc entries
struct StscEntry {
@@ -875,6 +878,9 @@ namespace
}
unsigned int offsetInChunk = 0;
if(samplesInChunk > sizeInfo.sampleCount - sampleIndex)
samplesInChunk = sizeInfo.sampleCount - sampleIndex;
for(unsigned int s = 0; s < samplesInChunk; ++s) {
sampleOffsets.push_back(chunkOffsets[chunkIdx] + offsetInChunk);