2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-05 11:50:53 +00:00

In JSONParser::handleToken refactor container creation

This commit is contained in:
m-holger 2023-01-27 14:37:25 +00:00
parent a39043f65e
commit 29093a167b

View File

@ -1294,6 +1294,7 @@ JSONParser::handleToken()
break;
case ps_top:
stack.push_back(item);
next_state = ps_done;
break;
@ -1320,36 +1321,30 @@ JSONParser::handleToken()
"JSONParser::handleToken: unexpected parser state");
}
if (reactor) {
if (item->isDictionary() || item->isArray()) {
stack.push_back(item);
ps_stack.push_back(next_state);
// Calling container start method is postponed until after
// adding the containers to their parent containers, if any.
// This makes it much easier to keep track of the current
// nesting level.
if (item->isDictionary()) {
reactor->dictionaryStart();
if (reactor) {
reactor->dictionaryStart();
}
next_state = ps_dict_begin;
} else if (item->isArray()) {
reactor->arrayStart();
if (reactor) {
reactor->arrayStart();
}
next_state = ps_array_begin;
}
}
// Prepare for next token
if (item->isDictionary()) {
stack.push_back(item);
ps_stack.push_back(next_state);
next_state = ps_dict_begin;
} else if (item->isArray()) {
stack.push_back(item);
ps_stack.push_back(next_state);
next_state = ps_array_begin;
} else if (parser_state == ps_top) {
stack.push_back(item);
}
if (ps_stack.size() > 500) {
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": maximum object depth exceeded");
if (ps_stack.size() > 500) {
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": maximum object depth exceeded");
}
}
parser_state = next_state;
}