mirror of
https://github.com/qpdf/qpdf.git
synced 2025-02-02 11:58:25 +00:00
In QPDFParser::parse refactor eof handling
This commit is contained in:
parent
37f7a73488
commit
26e0bf4610
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -1,14 +1,14 @@
|
||||
WARNING: bad16.pdf (trailer, offset 753): unexpected dictionary close token
|
||||
WARNING: bad16.pdf (trailer, offset 756): unexpected dictionary close token
|
||||
WARNING: bad16.pdf (trailer, offset 759): unknown token while reading object; treating as string
|
||||
WARNING: bad16.pdf (trailer, offset 779): unexpected EOF
|
||||
WARNING: bad16.pdf (trailer, offset 779): parse error while reading object
|
||||
WARNING: bad16.pdf (trailer, offset 779): unexpected EOF
|
||||
WARNING: bad16.pdf: file is damaged
|
||||
WARNING: bad16.pdf (offset 712): expected trailer dictionary
|
||||
WARNING: bad16.pdf: Attempting to reconstruct cross-reference table
|
||||
WARNING: bad16.pdf (trailer, offset 753): unexpected dictionary close token
|
||||
WARNING: bad16.pdf (trailer, offset 756): unexpected dictionary close token
|
||||
WARNING: bad16.pdf (trailer, offset 759): unknown token while reading object; treating as string
|
||||
WARNING: bad16.pdf (trailer, offset 779): unexpected EOF
|
||||
WARNING: bad16.pdf (trailer, offset 779): parse error while reading object
|
||||
WARNING: bad16.pdf (trailer, offset 779): unexpected EOF
|
||||
bad16.pdf: unable to find trailer dictionary while recovering damaged file
|
||||
|
@ -1,6 +1,6 @@
|
||||
WARNING: bad16.pdf (trailer, offset 753): unexpected dictionary close token
|
||||
WARNING: bad16.pdf (trailer, offset 756): unexpected dictionary close token
|
||||
WARNING: bad16.pdf (trailer, offset 759): unknown token while reading object; treating as string
|
||||
WARNING: bad16.pdf (trailer, offset 779): unexpected EOF
|
||||
WARNING: bad16.pdf (trailer, offset 779): parse error while reading object
|
||||
WARNING: bad16.pdf (trailer, offset 779): unexpected EOF
|
||||
bad16.pdf (offset 712): expected trailer dictionary
|
||||
|
Loading…
x
Reference in New Issue
Block a user