aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-01-27 15:37:25 +0100
committerm-holger <m-holger@kubitscheck.org>2023-02-04 14:53:23 +0100
commit29093a167b3f628d23b5a7890404eab659c6a685 (patch)
tree659bc2757beb1d648f1edf8c6245a2cfd41e2635
parenta39043f65eebdc24d98bdc29160ad489222c4ec3 (diff)
downloadqpdf-29093a167b3f628d23b5a7890404eab659c6a685.tar.zst
In JSONParser::handleToken refactor container creation
-rw-r--r--libqpdf/JSON.cc39
1 files changed, 17 insertions, 22 deletions
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc
index a16718de..41481660 100644
--- a/libqpdf/JSON.cc
+++ b/libqpdf/JSON.cc
@@ -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;
}