mirror of
https://github.com/taglib/taglib.git
synced 2026-08-14 06:17:00 -04:00
FLAC: limit metadata block count (#1396)
FLAC metadata scanning retained an unbounded number of blocks. A crafted file with many small blocks could consume disproportionate memory. Reject files that exceed a maximum metadata block count.
This commit is contained in:
@@ -49,6 +49,7 @@ namespace
|
||||
constexpr long MaxPaddingLegnth = 1024 * 1024;
|
||||
|
||||
constexpr char LastBlockFlag = '\x80';
|
||||
constexpr unsigned int MAX_FLAC_METADATA_BLOCK_COUNT = 50000;
|
||||
} // namespace
|
||||
|
||||
class FLAC::File::FilePrivate
|
||||
@@ -627,8 +628,15 @@ void FLAC::File::scan()
|
||||
nextBlockOffset += 4;
|
||||
d->flacStart = nextBlockOffset;
|
||||
|
||||
unsigned int blockCount = 0;
|
||||
while(true) {
|
||||
|
||||
if(blockCount++ >= MAX_FLAC_METADATA_BLOCK_COUNT) {
|
||||
debug("FLAC::File::scan() -- Maximum metadata block count exceeded");
|
||||
setValid(false);
|
||||
return;
|
||||
}
|
||||
|
||||
seek(nextBlockOffset);
|
||||
const ByteVector header = readBlock(4);
|
||||
if(header.size() != 4) {
|
||||
|
||||
Reference in New Issue
Block a user