Do not store too large FLAC metadata blocks (#1249) (#1250)

The size of FLAC metadata blocks is stored in only 24 bits. Remove
blocks exceeding this limit when saving FLAC and Ogg FLAC files.
This commit is contained in:
Urs Fleisch 2024-11-14 17:43:18 +01:00 committed by GitHub
parent 5b6f9ef848
commit 90f62a3c94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View File

@ -265,12 +265,19 @@ bool FLAC::File::save()
// Render data for the metadata blocks
ByteVector data;
for(const auto &block : std::as_const(d->blocks)) {
ByteVector blockData = block->render();
for(auto it = d->blocks.begin(); it != d->blocks.end();) {
ByteVector blockData = (*it)->render();
ByteVector blockHeader = ByteVector::fromUInt(blockData.size());
blockHeader[0] = block->code();
if(blockHeader[0] != 0) {
debug("FLAC::File::save() -- Removing too large block.");
delete *it;
it = d->blocks.erase(it);
continue;
}
blockHeader[0] = (*it)->code();
data.append(blockHeader);
data.append(blockData);
++it;
}
// Compute the amount of padding, and append that to data.

View File

@ -113,6 +113,17 @@ bool Ogg::FLAC::File::save()
// Put the size in the first 32 bit (I assume no more than 24 bit are used)
ByteVector v = ByteVector::fromUInt(d->xiphCommentData.size());
if(v[0] != 0) {
// Block size uses more than 24 bits, try again with pictures removed.
d->comment->removeAllPictures();
d->xiphCommentData = d->comment->render(false);
v = ByteVector::fromUInt(d->xiphCommentData.size());
if(v[0] != 0) {
debug("Ogg::FLAC::File::save() -- Invalid, metadata block is too large.");
return false;
}
debug("Ogg::FLAC::File::save() -- Metadata block is too large, pictures removed.");
}
// Set the type of the metadata-block to be a Xiph / Vorbis comment