diff options
author | m-holger <m-holger@kubitscheck.org> | 2023-10-27 16:37:46 +0200 |
---|---|---|
committer | m-holger <m-holger@kubitscheck.org> | 2023-11-01 16:23:30 +0100 |
commit | 26e0bf461041856ea8159c86556524e4b158efe7 (patch) | |
tree | 2627503edd3e36c9420fb6cab8b3bbfa8e7b33c4 /libqpdf | |
parent | 37f7a734885f0d3c9dce64fbdb9a57192170686b (diff) | |
download | qpdf-26e0bf461041856ea8159c86556524e4b158efe7.tar.zst |
In QPDFParser::parse refactor eof handling
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; |