mirror of
https://github.com/taglib/taglib.git
synced 2026-08-14 06:17:00 -04:00
Ogg FLAC: limit metadata block count (#1399)
Ogg FLAC scans metadata blocks by repeatedly fetching Ogg packets. Each packet lookup walks indexed pages from their beginning, so a file with many small metadata blocks has quadratic parsing time and page allocation. Limit the metadata block count to 1024. This keeps the worst-case scan bounded while allowing more than normal Ogg FLAC files require.
This commit is contained in:
@@ -32,6 +32,10 @@
|
||||
using namespace TagLib;
|
||||
using TagLib::FLAC::Properties;
|
||||
|
||||
namespace {
|
||||
constexpr int MAX_OGG_FLAC_METADATA_BLOCK_COUNT = 1024;
|
||||
}
|
||||
|
||||
class Ogg::FLAC::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
@@ -223,6 +227,7 @@ void Ogg::FLAC::File::scan()
|
||||
return;
|
||||
|
||||
int ipacket = 0;
|
||||
int blockCount = 1;
|
||||
offset_t overhead = 0;
|
||||
|
||||
ByteVector metadataHeader = packet(ipacket);
|
||||
@@ -287,6 +292,10 @@ void Ogg::FLAC::File::scan()
|
||||
// Search through the remaining metadata
|
||||
|
||||
while(!lastBlock) {
|
||||
if(blockCount++ >= MAX_OGG_FLAC_METADATA_BLOCK_COUNT) {
|
||||
debug("Ogg::FLAC::File::scan() -- Maximum metadata block count exceeded");
|
||||
return;
|
||||
}
|
||||
metadataHeader = packet(++ipacket);
|
||||
header = metadataHeader.mid(0, 4);
|
||||
if(header.size() != 4) {
|
||||
|
||||
Reference in New Issue
Block a user