mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2026-02-19 14:46:28 +00:00
fix: change abort when no parsing progress is made
Previously, no parsing progress (detecting infinite loops) was detected by an empty Node. This falsely triggers an abort, if an empty YAML document is being parsed. Instead, we detect if progress in the parsing stream is made, by comparing token positions. As long as new tokens are being parsed (detected by position change), we assume we are not in an infinite loop.
This commit is contained in:
committed by
Jesse Beder
parent
f3f123cea0
commit
f25f110e33
@@ -53,7 +53,7 @@ std::vector<Node> LoadAll(std::istream& input) {
|
|||||||
Parser parser(input);
|
Parser parser(input);
|
||||||
while (true) {
|
while (true) {
|
||||||
NodeBuilder builder;
|
NodeBuilder builder;
|
||||||
if (!parser.HandleNextDocument(builder) || builder.Root().IsNull()) {
|
if (!parser.HandleNextDocument(builder)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
docs.push_back(builder.Root());
|
docs.push_back(builder.Root());
|
||||||
|
|||||||
@@ -33,11 +33,26 @@ bool Parser::HandleNextDocument(EventHandler& eventHandler) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto oldPos = m_pScanner->peek().mark.pos;
|
||||||
|
|
||||||
SingleDocParser sdp(*m_pScanner, *m_pDirectives);
|
SingleDocParser sdp(*m_pScanner, *m_pDirectives);
|
||||||
sdp.HandleDocument(eventHandler);
|
sdp.HandleDocument(eventHandler);
|
||||||
|
|
||||||
|
// checks if progress was made
|
||||||
|
// 1. if scanner has no more tokens, progress was made
|
||||||
|
if (m_pScanner->empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. if token position has changed, progress was made
|
||||||
|
auto newPos = m_pScanner->peek().mark.pos;
|
||||||
|
if (newPos != oldPos) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// No progress was made, no further processing
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Parser::ParseDirectives() {
|
void Parser::ParseDirectives() {
|
||||||
bool readDirective = false;
|
bool readDirective = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user