Fix crash with invalid WAV files (#1163) (#1164)

With specially crafted WAV files having the "id3 " chunk as the
only valid chunk, when trying to write the tags, the existing
"id3 " chunk is removed, and then vector::front() is called on
the now empty chunks vector.
Now it is checked if the vector is empty to avoid the crash.
This commit is contained in:
Urs Fleisch
2023-11-05 14:40:18 +01:00
committed by GitHub
parent f202fa25c3
commit dfa33bec08
3 changed files with 21 additions and 0 deletions

View File

@ -361,6 +361,9 @@ void RIFF::File::writeChunk(const ByteVector &name, const ByteVector &data,
void RIFF::File::updateGlobalSize()
{
if(d->chunks.empty())
return;
const Chunk first = d->chunks.front();
const Chunk last = d->chunks.back();
d->size = static_cast<unsigned int>(last.offset + last.size + last.padding - first.offset + 12);