From 5e1cb4081d8f23532b6b3ec2ee173f3d7c64492a Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Fri, 24 Apr 2026 18:52:45 +0200 Subject: [PATCH] Limit MP4 atom sibling count at top level (#1344) --- taglib/mp4/mp4atom.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 935b3fb7..24578b6b 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -222,6 +222,8 @@ public: MP4::Atoms::Atoms(File *file) : d(std::make_unique()) { + static constexpr int MAX_MP4_ATOM_COUNT_PER_LEVEL = 5000; + d->atoms.setAutoDelete(true); file->seek(0, File::End); @@ -232,6 +234,13 @@ MP4::Atoms::Atoms(File *file) : d->atoms.append(atom); if (atom->length() == 0) break; + + if(d->atoms.size() > MAX_MP4_ATOM_COUNT_PER_LEVEL) { + debug("MP4: Maximum atom count exceeded"); + // Make sure the file is detected as invalid. + d->atoms.clear(); + break; + } } }