mirror of
https://github.com/taglib/taglib.git
synced 2026-08-14 06:17:00 -04:00
Matroska: limit elements in EBML containers (#1393)
EBML containers could contain an unbounded number of small elements. The parser retained each element, allowing a crafted Matroska file to consume disproportionate memory. Reject containers that exceed a per-level element count limit.
This commit is contained in:
@@ -101,6 +101,7 @@ void EBML::MasterElement::setMinRenderSize(offset_t minimumSize)
|
||||
bool EBML::MasterElement::read(File &file, int depth)
|
||||
{
|
||||
static constexpr int MAX_EBML_DEPTH = 64;
|
||||
static constexpr int MAX_EBML_ELEMENT_COUNT_PER_LEVEL = 50000;
|
||||
if(depth > MAX_EBML_DEPTH) {
|
||||
debug("EBML: Maximum nesting depth exceeded");
|
||||
return false;
|
||||
@@ -108,6 +109,10 @@ bool EBML::MasterElement::read(File &file, int depth)
|
||||
const offset_t maxOffset = file.tell() + dataSize;
|
||||
std::unique_ptr<Element> element;
|
||||
while((element = findNextElement(file, maxOffset))) {
|
||||
if(elements.size() >= MAX_EBML_ELEMENT_COUNT_PER_LEVEL) {
|
||||
debug("EBML: Maximum element count exceeded");
|
||||
return false;
|
||||
}
|
||||
if(auto master = dynamic_cast<MasterElement *>(element.get())) {
|
||||
if(!master->read(file, depth + 1)) {
|
||||
debug("EBML: Invalid MasterElement");
|
||||
|
||||
Reference in New Issue
Block a user