Commit d904eab84c008325289bfb7ddcf60256b36a1b67

Authored by m-holger
1 parent 90829228

In QPDFParser::parse refactor handling of array_open and dict_open tokens

libqpdf/QPDFParser.cc
... ... @@ -227,20 +227,15 @@ QPDFParser::parse(bool& empty, bool content_stream)
227 227 if (stack.size() > 500) {
228 228 QTC::TC("qpdf", "QPDFParser too deep");
229 229 warn("ignoring excessively deeply nested data structure");
230   - if (tooManyBadTokens()) {
231   - return {QPDF_Null::create()};
232   - }
233   - is_null = true;
234   - state = st_top;
  230 + return {QPDF_Null::create()};
235 231 } else {
236   - state = st_start;
237 232 state_stack.push_back(
238 233 (tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array
239 234 : st_dictionary);
240 235 b_contents = false;
241 236 stack.emplace_back(input);
  237 + continue;
242 238 }
243   - break;
244 239  
245 240 case QPDFTokenizer::tt_bool:
246 241 object = QPDF_Bool::create((tokenizer.getValue() == "true"));
... ... @@ -349,7 +344,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
349 344 break;
350 345 }
351 346  
352   - if (object == nullptr && !is_null && state != st_start) {
  347 + if (object == nullptr && !is_null) {
353 348 throw std::logic_error("QPDFParser:parseInternal: unexpected uninitialized object");
354 349 }
355 350  
... ... @@ -369,9 +364,6 @@ QPDFParser::parse(bool& empty, bool content_stream)
369 364 case st_top:
370 365 done = true;
371 366 break;
372   -
373   - case st_start:
374   - break;
375 367 }
376 368 }
377 369  
... ...
libqpdf/qpdf/QPDFParser.hh
... ... @@ -31,7 +31,7 @@ class QPDFParser
31 31 QPDFObjectHandle parse(bool& empty, bool content_stream);
32 32  
33 33 private:
34   - enum parser_state_e { st_top, st_start, st_dictionary, st_array };
  34 + enum parser_state_e { st_top, st_dictionary, st_array };
35 35  
36 36 bool tooManyBadTokens();
37 37 void warn(qpdf_offset_t offset, std::string const& msg) const;
... ...