Skip to content

Commit 90f62a3

Browse files
authored
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.
1 parent 5b6f9ef commit 90f62a3

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

taglib/flac/flacfile.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,19 @@ bool FLAC::File::save()
265265
// Render data for the metadata blocks
266266

267267
ByteVector data;
268-
for(const auto &block : std::as_const(d->blocks)) {
269-
ByteVector blockData = block->render();
268+
for(auto it = d->blocks.begin(); it != d->blocks.end();) {
269+
ByteVector blockData = (*it)->render();
270270
ByteVector blockHeader = ByteVector::fromUInt(blockData.size());
271-
blockHeader[0] = block->code();
271+
if(blockHeader[0] != 0) {
272+
debug("FLAC::File::save() -- Removing too large block.");
273+
delete *it;
274+
it = d->blocks.erase(it);
275+
continue;
276+
}
277+
blockHeader[0] = (*it)->code();
272278
data.append(blockHeader);
273279
data.append(blockData);
280+
++it;
274281
}
275282

276283
// Compute the amount of padding, and append that to data.

taglib/ogg/flac/oggflacfile.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ bool Ogg::FLAC::File::save()
113113
// Put the size in the first 32 bit (I assume no more than 24 bit are used)
114114

115115
ByteVector v = ByteVector::fromUInt(d->xiphCommentData.size());
116+
if(v[0] != 0) {
117+
// Block size uses more than 24 bits, try again with pictures removed.
118+
d->comment->removeAllPictures();
119+
d->xiphCommentData = d->comment->render(false);
120+
v = ByteVector::fromUInt(d->xiphCommentData.size());
121+
if(v[0] != 0) {
122+
debug("Ogg::FLAC::File::save() -- Invalid, metadata block is too large.");
123+
return false;
124+
}
125+
debug("Ogg::FLAC::File::save() -- Metadata block is too large, pictures removed.");
126+
}
116127

117128
// Set the type of the metadata-block to be a Xiph / Vorbis comment
118129

0 commit comments

Comments
 (0)