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