diff options
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDFParser.cc | 29 | ||||
-rw-r--r-- | libqpdf/qpdf/QPDFParser.hh | 2 |
2 files changed, 11 insertions, 20 deletions
diff --git a/libqpdf/QPDFParser.cc b/libqpdf/QPDFParser.cc index 18b60d53..2a7598c9 100644 --- a/libqpdf/QPDFParser.cc +++ b/libqpdf/QPDFParser.cc @@ -81,12 +81,16 @@ QPDFParser::parse(bool& empty, bool content_stream) switch (tokenizer.getType()) { case QPDFTokenizer::tt_eof: - if (!content_stream) { - QTC::TC("qpdf", "QPDFParser eof in parse"); - warn("unexpected EOF"); + if (state_stack.size() > 1) { + warn("parse error while reading object"); } - state = st_eof; - break; + if (content_stream) { + // In content stream mode, leave object uninitialized to indicate EOF + return {}; + } + QTC::TC("qpdf", "QPDFParser eof in parse"); + warn("unexpected EOF"); + return {QPDF_Null::create()}; case QPDFTokenizer::tt_bad: QTC::TC("qpdf", "QPDFParser bad token in parse"); @@ -259,24 +263,11 @@ QPDFParser::parse(bool& empty, bool content_stream) break; } - if (object == nullptr && !is_null && - (!((state == st_start) || (state == st_stop) || (state == st_eof)))) { + if (object == nullptr && !is_null && (!(state == st_start || state == st_stop))) { throw std::logic_error("QPDFParser:parseInternal: unexpected uninitialized object"); - is_null = true; } switch (state) { - case st_eof: - if (state_stack.size() > 1) { - warn("parse error while reading object"); - } - done = true; - // In content stream mode, leave object uninitialized to indicate EOF - if (!content_stream) { - is_null = true; - } - break; - case st_dictionary: case st_array: if (is_null) { diff --git a/libqpdf/qpdf/QPDFParser.hh b/libqpdf/qpdf/QPDFParser.hh index 2107a9b8..5697e7d8 100644 --- a/libqpdf/qpdf/QPDFParser.hh +++ b/libqpdf/qpdf/QPDFParser.hh @@ -31,7 +31,7 @@ class QPDFParser QPDFObjectHandle parse(bool& empty, bool content_stream); private: - enum parser_state_e { st_top, st_start, st_stop, st_eof, st_dictionary, st_array }; + enum parser_state_e { st_top, st_start, st_stop, st_dictionary, st_array }; bool tooManyBadTokens(); void warn(qpdf_offset_t offset, std::string const& msg) const; |