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:
Acts1631
2026-08-04 06:10:22 +02:00
committed by GitHub
parent 2ada48a77f
commit eb4ba7e93b
+8
View File
@@ -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) {