mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-02 03:42:30 +00:00
parent
6670c685ab
commit
8ad1ea34fe
@ -55,28 +55,14 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
std::string const& token_error_message = token.getErrorMessage();
|
std::string const& token_error_message = token.getErrorMessage();
|
||||||
if (!token_error_message.empty()) {
|
if (!token_error_message.empty()) {
|
||||||
// Tokens other than tt_bad can still generate warnings.
|
// Tokens other than tt_bad can still generate warnings.
|
||||||
warn(
|
warn(token_error_message);
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
token_error_message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (token.getType()) {
|
switch (token.getType()) {
|
||||||
case QPDFTokenizer::tt_eof:
|
case QPDFTokenizer::tt_eof:
|
||||||
if (!content_stream) {
|
if (!content_stream) {
|
||||||
QTC::TC("qpdf", "QPDFParser eof in parse");
|
QTC::TC("qpdf", "QPDFParser eof in parse");
|
||||||
warn(
|
warn("unexpected EOF");
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"unexpected EOF"));
|
|
||||||
}
|
}
|
||||||
bad = true;
|
bad = true;
|
||||||
state = st_eof;
|
state = st_eof;
|
||||||
@ -91,14 +77,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
case QPDFTokenizer::tt_brace_open:
|
case QPDFTokenizer::tt_brace_open:
|
||||||
case QPDFTokenizer::tt_brace_close:
|
case QPDFTokenizer::tt_brace_close:
|
||||||
QTC::TC("qpdf", "QPDFParser bad brace");
|
QTC::TC("qpdf", "QPDFParser bad brace");
|
||||||
warn(
|
warn("treating unexpected brace token as null");
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"treating unexpected brace token as null"));
|
|
||||||
bad = true;
|
bad = true;
|
||||||
object = QPDFObjectHandle::newNull();
|
object = QPDFObjectHandle::newNull();
|
||||||
break;
|
break;
|
||||||
@ -108,14 +87,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
state = st_stop;
|
state = st_stop;
|
||||||
} else {
|
} else {
|
||||||
QTC::TC("qpdf", "QPDFParser bad array close");
|
QTC::TC("qpdf", "QPDFParser bad array close");
|
||||||
warn(
|
warn("treating unexpected array close token as null");
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"treating unexpected array close token as null"));
|
|
||||||
bad = true;
|
bad = true;
|
||||||
object = QPDFObjectHandle::newNull();
|
object = QPDFObjectHandle::newNull();
|
||||||
}
|
}
|
||||||
@ -126,14 +98,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
state = st_stop;
|
state = st_stop;
|
||||||
} else {
|
} else {
|
||||||
QTC::TC("qpdf", "QPDFParser bad dictionary close");
|
QTC::TC("qpdf", "QPDFParser bad dictionary close");
|
||||||
warn(
|
warn("unexpected dictionary close token");
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"unexpected dictionary close token"));
|
|
||||||
bad = true;
|
bad = true;
|
||||||
object = QPDFObjectHandle::newNull();
|
object = QPDFObjectHandle::newNull();
|
||||||
}
|
}
|
||||||
@ -143,14 +108,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
case QPDFTokenizer::tt_dict_open:
|
case QPDFTokenizer::tt_dict_open:
|
||||||
if (olist_stack.size() > 500) {
|
if (olist_stack.size() > 500) {
|
||||||
QTC::TC("qpdf", "QPDFParser too deep");
|
QTC::TC("qpdf", "QPDFParser too deep");
|
||||||
warn(
|
warn("ignoring excessively deeply nested data structure");
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"ignoring excessively deeply nested data structure"));
|
|
||||||
bad = true;
|
bad = true;
|
||||||
object = QPDFObjectHandle::newNull();
|
object = QPDFObjectHandle::newNull();
|
||||||
state = st_top;
|
state = st_top;
|
||||||
@ -233,15 +191,8 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
empty = true;
|
empty = true;
|
||||||
} else {
|
} else {
|
||||||
QTC::TC("qpdf", "QPDFParser treat word as string");
|
QTC::TC("qpdf", "QPDFParser treat word as string");
|
||||||
warn(
|
warn("unknown token while reading object;"
|
||||||
context,
|
" treating as string");
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"unknown token while reading object;"
|
|
||||||
" treating as string"));
|
|
||||||
bad = true;
|
bad = true;
|
||||||
object = QPDFObjectHandle::newString(value);
|
object = QPDFObjectHandle::newString(value);
|
||||||
}
|
}
|
||||||
@ -265,15 +216,8 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
warn(
|
warn("treating unknown token type as null while "
|
||||||
context,
|
"reading object");
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"treating unknown token type as null while "
|
|
||||||
"reading object"));
|
|
||||||
bad = true;
|
bad = true;
|
||||||
object = QPDFObjectHandle::newNull();
|
object = QPDFObjectHandle::newNull();
|
||||||
break;
|
break;
|
||||||
@ -299,14 +243,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
if (bad_count > 5) {
|
if (bad_count > 5) {
|
||||||
// We had too many consecutive errors without enough
|
// We had too many consecutive errors without enough
|
||||||
// intervening successful objects. Give up.
|
// intervening successful objects. Give up.
|
||||||
warn(
|
warn("too many errors; giving up on reading object");
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"too many errors; giving up on reading object"));
|
|
||||||
state = st_top;
|
state = st_top;
|
||||||
object = QPDFObjectHandle::newNull();
|
object = QPDFObjectHandle::newNull();
|
||||||
}
|
}
|
||||||
@ -314,14 +251,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case st_eof:
|
case st_eof:
|
||||||
if (state_stack.size() > 1) {
|
if (state_stack.size() > 1) {
|
||||||
warn(
|
warn("parse error while reading object");
|
||||||
context,
|
|
||||||
QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
input->getLastOffset(),
|
|
||||||
"parse error while reading object"));
|
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
// In content stream mode, leave object uninitialized to
|
// In content stream mode, leave object uninitialized to
|
||||||
@ -404,28 +334,18 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
(found_fake ? 0 : 1));
|
(found_fake ? 0 : 1));
|
||||||
}
|
}
|
||||||
warn(
|
warn(
|
||||||
context,
|
offset,
|
||||||
QPDFExc(
|
"expected dictionary key but found"
|
||||||
qpdf_e_damaged_pdf,
|
" non-name object; inserting key " +
|
||||||
input->getName(),
|
candidate);
|
||||||
object_description,
|
|
||||||
offset,
|
|
||||||
"expected dictionary key but found"
|
|
||||||
" non-name object; inserting key " +
|
|
||||||
candidate));
|
|
||||||
val = key_obj;
|
val = key_obj;
|
||||||
key_obj = QPDFObjectHandle::newName(candidate);
|
key_obj = QPDFObjectHandle::newName(candidate);
|
||||||
} else if (i + 1 >= olist.size()) {
|
} else if (i + 1 >= olist.size()) {
|
||||||
QTC::TC("qpdf", "QPDFParser no val for last key");
|
QTC::TC("qpdf", "QPDFParser no val for last key");
|
||||||
warn(
|
warn(
|
||||||
context,
|
offset,
|
||||||
QPDFExc(
|
"dictionary ended prematurely; "
|
||||||
qpdf_e_damaged_pdf,
|
"using null as value for last key");
|
||||||
input->getName(),
|
|
||||||
object_description,
|
|
||||||
offset,
|
|
||||||
"dictionary ended prematurely; "
|
|
||||||
"using null as value for last key"));
|
|
||||||
val = QPDFObjectHandle::newNull();
|
val = QPDFObjectHandle::newNull();
|
||||||
QPDFObjectHandle::setObjectDescriptionFromInput(
|
QPDFObjectHandle::setObjectDescriptionFromInput(
|
||||||
val, context, object_description, input, offset);
|
val, context, object_description, input, offset);
|
||||||
@ -436,15 +356,10 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
|||||||
if (dict.count(key) > 0) {
|
if (dict.count(key) > 0) {
|
||||||
QTC::TC("qpdf", "QPDFParser duplicate dict key");
|
QTC::TC("qpdf", "QPDFParser duplicate dict key");
|
||||||
warn(
|
warn(
|
||||||
context,
|
offset,
|
||||||
QPDFExc(
|
"dictionary has duplicated key " + key +
|
||||||
qpdf_e_damaged_pdf,
|
"; last occurrence overrides earlier "
|
||||||
input->getName(),
|
"ones");
|
||||||
object_description,
|
|
||||||
offset,
|
|
||||||
"dictionary has duplicated key " + key +
|
|
||||||
"; last occurrence overrides earlier "
|
|
||||||
"ones"));
|
|
||||||
}
|
}
|
||||||
dict[key] = val;
|
dict[key] = val;
|
||||||
}
|
}
|
||||||
@ -501,3 +416,22 @@ QPDFParser::warn(QPDF* qpdf, QPDFExc const& e)
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const
|
||||||
|
{
|
||||||
|
warn(
|
||||||
|
context,
|
||||||
|
QPDFExc(
|
||||||
|
qpdf_e_damaged_pdf,
|
||||||
|
input->getName(),
|
||||||
|
object_description,
|
||||||
|
offset,
|
||||||
|
msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFParser::warn(std::string const& msg) const
|
||||||
|
{
|
||||||
|
warn(input->getLastOffset(), msg);
|
||||||
|
}
|
||||||
|
@ -37,6 +37,8 @@ class QPDFParser
|
|||||||
st_array
|
st_array
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void warn(qpdf_offset_t offset, std::string const& msg) const;
|
||||||
|
void warn(std::string const& msg) const;
|
||||||
static void warn(QPDF*, QPDFExc const&);
|
static void warn(QPDF*, QPDFExc const&);
|
||||||
void setParsedOffset(qpdf_offset_t offset);
|
void setParsedOffset(qpdf_offset_t offset);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user