From d781aaed7f9d71aa9eeaf61c057df15c49acc39e Mon Sep 17 00:00:00 2001 From: Acts1631 <69813585+acts-1631@users.noreply.github.com> Date: Wed, 5 Aug 2026 14:29:11 -0400 Subject: [PATCH] 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. --- taglib/ogg/flac/oggflacfile.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/taglib/ogg/flac/oggflacfile.cpp b/taglib/ogg/flac/oggflacfile.cpp index a2f3ae60..a71dc72b 100644 --- a/taglib/ogg/flac/oggflacfile.cpp +++ b/taglib/ogg/flac/oggflacfile.cpp @@ -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) {