mirror of
https://github.com/taglib/taglib.git
synced 2025-05-25 20:20:25 -04:00
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:
parent
5b6f9ef848
commit
90f62a3c94
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user