Index: yaml-cpp-0.5.1/src/singledocparser.cpp =================================================================== --- yaml-cpp-0.5.1/src/singledocparser.cpp +++ yaml-cpp-0.5.1/src/singledocparser.cpp 2018-11-19 21:05:08.826885213 +0100 @@ -12,7 +12,7 @@ namespace YAML { - SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives): m_scanner(scanner), m_directives(directives), m_pCollectionStack(new CollectionStack), m_curAnchor(0) + SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives): depth(0), depth_limit(2048), m_scanner(scanner), m_directives(directives), m_pCollectionStack(new CollectionStack), m_curAnchor(0) { } @@ -46,6 +46,10 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) { + if (depth > depth_limit) { + throw ParserException(m_scanner.mark(), ErrorMsg::BAD_FILE); + } + // an empty node *is* a possibility if(m_scanner.empty()) { eventHandler.OnNull(m_scanner.mark(), NullAnchor); @@ -57,9 +61,11 @@ // special case: a value node by itself must be a map, with no header if(m_scanner.peek().type == Token::VALUE) { + depth++; eventHandler.OnMapStart(mark, "?", NullAnchor); HandleMap(eventHandler); eventHandler.OnMapEnd(); + depth--; return; } @@ -95,22 +101,28 @@ return; case Token::FLOW_SEQ_START: case Token::BLOCK_SEQ_START: + depth++; eventHandler.OnSequenceStart(mark, tag, anchor); HandleSequence(eventHandler); eventHandler.OnSequenceEnd(); + depth--; return; case Token::FLOW_MAP_START: case Token::BLOCK_MAP_START: + depth++; eventHandler.OnMapStart(mark, tag, anchor); HandleMap(eventHandler); eventHandler.OnMapEnd(); + depth--; return; case Token::KEY: // compact maps can only go in a flow sequence if(m_pCollectionStack->GetCurCollectionType() == CollectionType::FlowSeq) { + depth++; eventHandler.OnMapStart(mark, tag, anchor); HandleMap(eventHandler); eventHandler.OnMapEnd(); + depth--; return; } break; Index: yaml-cpp-0.5.1/src/singledocparser.h =================================================================== --- yaml-cpp-0.5.1/src/singledocparser.h +++ yaml-cpp-0.5.1/src/singledocparser.h 2018-11-19 21:04:44.364042993 +0100 @@ -51,6 +51,8 @@ anchor_t LookupAnchor(const Mark& mark, const std::string& name) const; private: + int depth; + int depth_limit; Scanner& m_scanner; const Directives& m_directives; std::auto_ptr<CollectionStack> m_pCollectionStack;