File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments