2022-08-16 12:59:32 +00:00
|
|
|
#include <qpdf/QPDFParser.hh>
|
|
|
|
|
|
|
|
#include <qpdf/QPDF.hh>
|
2022-08-10 12:16:06 +00:00
|
|
|
#include <qpdf/QPDFObjGen.hh>
|
2022-08-16 12:59:32 +00:00
|
|
|
#include <qpdf/QPDFObjectHandle.hh>
|
2022-12-15 09:56:46 +00:00
|
|
|
#include <qpdf/QPDFObject_private.hh>
|
2022-12-19 10:50:46 +00:00
|
|
|
#include <qpdf/QPDF_Array.hh>
|
|
|
|
#include <qpdf/QPDF_Bool.hh>
|
|
|
|
#include <qpdf/QPDF_Dictionary.hh>
|
|
|
|
#include <qpdf/QPDF_InlineImage.hh>
|
|
|
|
#include <qpdf/QPDF_Integer.hh>
|
|
|
|
#include <qpdf/QPDF_Name.hh>
|
|
|
|
#include <qpdf/QPDF_Null.hh>
|
|
|
|
#include <qpdf/QPDF_Operator.hh>
|
|
|
|
#include <qpdf/QPDF_Real.hh>
|
|
|
|
#include <qpdf/QPDF_Reserved.hh>
|
|
|
|
#include <qpdf/QPDF_Stream.hh>
|
|
|
|
#include <qpdf/QPDF_String.hh>
|
|
|
|
#include <qpdf/QPDF_Unresolved.hh>
|
2022-08-16 12:59:32 +00:00
|
|
|
#include <qpdf/QTC.hh>
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
2022-12-19 10:50:46 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2022-08-30 11:53:19 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct StackFrame
|
|
|
|
{
|
|
|
|
StackFrame(std::shared_ptr<InputSource> input) :
|
2023-03-26 19:02:49 +00:00
|
|
|
offset(input->tell())
|
2022-08-30 11:53:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-19 11:41:09 +00:00
|
|
|
std::vector<std::shared_ptr<QPDFObject>> olist;
|
2022-08-30 11:53:19 +00:00
|
|
|
qpdf_offset_t offset;
|
2023-03-26 19:02:49 +00:00
|
|
|
std::string contents_string{""};
|
|
|
|
qpdf_offset_t contents_offset{-1};
|
|
|
|
int null_count{0};
|
2022-08-30 11:53:19 +00:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2022-08-16 12:59:32 +00:00
|
|
|
QPDFObjectHandle
|
|
|
|
QPDFParser::parse(bool& empty, bool content_stream)
|
|
|
|
{
|
|
|
|
// This method must take care not to resolve any objects. Don't
|
|
|
|
// check the type of any object without first ensuring that it is
|
|
|
|
// a direct object. Otherwise, doing so may have the side effect
|
|
|
|
// of reading the object and changing the file pointer. If you do
|
|
|
|
// this, it will cause a logic error to be thrown from
|
|
|
|
// QPDF::inParse().
|
|
|
|
|
2023-03-26 19:02:49 +00:00
|
|
|
const static std::shared_ptr<QPDFObject> null_oh = QPDF_Null::create();
|
2022-08-16 12:59:32 +00:00
|
|
|
QPDF::ParseGuard pg(context);
|
|
|
|
|
|
|
|
empty = false;
|
|
|
|
|
2022-12-19 10:50:46 +00:00
|
|
|
std::shared_ptr<QPDFObject> object;
|
2022-08-16 12:59:32 +00:00
|
|
|
bool set_offset = false;
|
|
|
|
|
2022-08-30 11:53:19 +00:00
|
|
|
std::vector<StackFrame> stack;
|
|
|
|
stack.push_back(StackFrame(input));
|
2022-08-16 12:59:32 +00:00
|
|
|
std::vector<parser_state_e> state_stack;
|
|
|
|
state_stack.push_back(st_top);
|
2022-08-30 11:53:19 +00:00
|
|
|
qpdf_offset_t offset;
|
2022-08-16 12:59:32 +00:00
|
|
|
bool done = false;
|
|
|
|
int bad_count = 0;
|
|
|
|
int good_count = 0;
|
|
|
|
bool b_contents = false;
|
2022-08-30 12:32:54 +00:00
|
|
|
bool is_null = false;
|
2022-08-30 11:53:19 +00:00
|
|
|
|
2022-08-16 12:59:32 +00:00
|
|
|
while (!done) {
|
|
|
|
bool bad = false;
|
2022-08-10 12:16:06 +00:00
|
|
|
bool indirect_ref = false;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = false;
|
2022-08-30 11:53:19 +00:00
|
|
|
auto& frame = stack.back();
|
|
|
|
auto& olist = frame.olist;
|
2022-08-16 12:59:32 +00:00
|
|
|
parser_state_e state = state_stack.back();
|
2022-08-30 11:53:19 +00:00
|
|
|
offset = frame.offset;
|
2022-08-16 12:59:32 +00:00
|
|
|
|
2022-12-19 10:50:46 +00:00
|
|
|
object = nullptr;
|
2022-08-16 12:59:32 +00:00
|
|
|
set_offset = false;
|
|
|
|
|
2022-10-05 18:42:02 +00:00
|
|
|
if (!tokenizer.nextToken(*input, object_description)) {
|
|
|
|
warn(tokenizer.getErrorMessage());
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:42:02 +00:00
|
|
|
switch (tokenizer.getType()) {
|
2022-08-16 12:59:32 +00:00
|
|
|
case QPDFTokenizer::tt_eof:
|
|
|
|
if (!content_stream) {
|
|
|
|
QTC::TC("qpdf", "QPDFParser eof in parse");
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("unexpected EOF");
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
bad = true;
|
|
|
|
state = st_eof;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_bad:
|
|
|
|
QTC::TC("qpdf", "QPDFParser bad token in parse");
|
|
|
|
bad = true;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_brace_open:
|
|
|
|
case QPDFTokenizer::tt_brace_close:
|
|
|
|
QTC::TC("qpdf", "QPDFParser bad brace");
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("treating unexpected brace token as null");
|
2022-08-16 12:59:32 +00:00
|
|
|
bad = true;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_array_close:
|
|
|
|
if (state == st_array) {
|
|
|
|
state = st_stop;
|
|
|
|
} else {
|
|
|
|
QTC::TC("qpdf", "QPDFParser bad array close");
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("treating unexpected array close token as null");
|
2022-08-16 12:59:32 +00:00
|
|
|
bad = true;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_dict_close:
|
|
|
|
if (state == st_dictionary) {
|
|
|
|
state = st_stop;
|
|
|
|
} else {
|
|
|
|
QTC::TC("qpdf", "QPDFParser bad dictionary close");
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("unexpected dictionary close token");
|
2022-08-16 12:59:32 +00:00
|
|
|
bad = true;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_array_open:
|
|
|
|
case QPDFTokenizer::tt_dict_open:
|
2022-08-30 11:53:19 +00:00
|
|
|
if (stack.size() > 500) {
|
2022-08-16 12:59:32 +00:00
|
|
|
QTC::TC("qpdf", "QPDFParser too deep");
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("ignoring excessively deeply nested data structure");
|
2022-08-16 12:59:32 +00:00
|
|
|
bad = true;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
state = st_top;
|
|
|
|
} else {
|
|
|
|
state = st_start;
|
|
|
|
state_stack.push_back(
|
2022-10-05 18:42:02 +00:00
|
|
|
(tokenizer.getType() == QPDFTokenizer::tt_array_open)
|
2022-08-16 12:59:32 +00:00
|
|
|
? st_array
|
|
|
|
: st_dictionary);
|
|
|
|
b_contents = false;
|
2022-08-30 11:53:19 +00:00
|
|
|
stack.push_back(StackFrame(input));
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_bool:
|
2022-10-05 18:42:02 +00:00
|
|
|
object = QPDF_Bool::create((tokenizer.getValue() == "true"));
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_null:
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2023-03-26 19:02:49 +00:00
|
|
|
++frame.null_count;
|
|
|
|
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_integer:
|
2022-12-19 10:50:46 +00:00
|
|
|
object = QPDF_Integer::create(
|
2022-10-05 18:42:02 +00:00
|
|
|
QUtil::string_to_ll(std::string(tokenizer.getValue()).c_str()));
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_real:
|
2022-10-05 18:42:02 +00:00
|
|
|
object = QPDF_Real::create(tokenizer.getValue());
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_name:
|
|
|
|
{
|
2022-10-05 18:42:02 +00:00
|
|
|
auto name = tokenizer.getValue();
|
2022-12-19 10:50:46 +00:00
|
|
|
object = QPDF_Name::create(name);
|
2022-08-16 12:59:32 +00:00
|
|
|
|
|
|
|
if (name == "/Contents") {
|
|
|
|
b_contents = true;
|
|
|
|
} else {
|
|
|
|
b_contents = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_word:
|
|
|
|
{
|
2022-10-05 18:42:02 +00:00
|
|
|
auto value = tokenizer.getValue();
|
2022-08-30 10:32:43 +00:00
|
|
|
auto size = olist.size();
|
2022-08-16 12:59:32 +00:00
|
|
|
if (content_stream) {
|
2022-12-19 10:50:46 +00:00
|
|
|
object = QPDF_Operator::create(value);
|
2022-08-16 12:59:32 +00:00
|
|
|
} else if (
|
2022-12-19 11:41:09 +00:00
|
|
|
value == "R" && state != st_top && size >= 2 &&
|
|
|
|
olist.back() &&
|
|
|
|
olist.back()->getTypeCode() == ::ot_integer &&
|
|
|
|
!olist.back()->getObjGen().isIndirect() &&
|
|
|
|
olist.at(size - 2) &&
|
|
|
|
olist.at(size - 2)->getTypeCode() == ::ot_integer &&
|
|
|
|
!olist.at(size - 2)->getObjGen().isIndirect()) {
|
2022-08-16 12:59:32 +00:00
|
|
|
if (context == nullptr) {
|
|
|
|
QTC::TC("qpdf", "QPDFParser indirect without context");
|
|
|
|
throw std::logic_error(
|
|
|
|
"QPDFObjectHandle::parse called without context"
|
|
|
|
" on an object with indirect references");
|
|
|
|
}
|
2022-08-10 12:16:06 +00:00
|
|
|
auto ref_og = QPDFObjGen(
|
2022-12-19 11:41:09 +00:00
|
|
|
QPDFObjectHandle(olist.at(size - 2)).getIntValueAsInt(),
|
|
|
|
QPDFObjectHandle(olist.back()).getIntValueAsInt());
|
2022-08-10 12:16:06 +00:00
|
|
|
if (ref_og.isIndirect()) {
|
2022-11-24 16:50:46 +00:00
|
|
|
// This action has the desirable side effect
|
|
|
|
// of causing dangling references (references
|
|
|
|
// to indirect objects that don't appear in
|
|
|
|
// the PDF) in any parsed object to appear in
|
|
|
|
// the object cache.
|
2022-12-19 10:50:46 +00:00
|
|
|
object = context->getObject(ref_og).obj;
|
2022-08-10 12:16:06 +00:00
|
|
|
indirect_ref = true;
|
|
|
|
} else {
|
|
|
|
QTC::TC("qpdf", "QPDFParser indirect with 0 objid");
|
|
|
|
is_null = true;
|
|
|
|
}
|
2022-08-30 10:32:43 +00:00
|
|
|
olist.pop_back();
|
|
|
|
olist.pop_back();
|
2022-08-16 12:59:32 +00:00
|
|
|
} else if ((value == "endobj") && (state == st_top)) {
|
|
|
|
// We just saw endobj without having read
|
|
|
|
// anything. Treat this as a null and do not move
|
|
|
|
// the input source's offset.
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
input->seek(input->getLastOffset(), SEEK_SET);
|
|
|
|
empty = true;
|
|
|
|
} else {
|
|
|
|
QTC::TC("qpdf", "QPDFParser treat word as string");
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("unknown token while reading object;"
|
|
|
|
" treating as string");
|
2022-08-16 12:59:32 +00:00
|
|
|
bad = true;
|
2022-12-19 10:50:46 +00:00
|
|
|
object = QPDF_String::create(value);
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QPDFTokenizer::tt_string:
|
|
|
|
{
|
2022-10-05 18:42:02 +00:00
|
|
|
auto val = tokenizer.getValue();
|
2022-08-16 12:59:32 +00:00
|
|
|
if (decrypter) {
|
|
|
|
if (b_contents) {
|
2022-08-30 11:53:19 +00:00
|
|
|
frame.contents_string = val;
|
|
|
|
frame.contents_offset = input->getLastOffset();
|
2022-08-16 12:59:32 +00:00
|
|
|
b_contents = false;
|
|
|
|
}
|
2022-10-05 18:42:02 +00:00
|
|
|
std::string s{val};
|
|
|
|
decrypter->decryptString(s);
|
|
|
|
object = QPDF_String::create(s);
|
|
|
|
} else {
|
|
|
|
object = QPDF_String::create(val);
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("treating unknown token type as null while "
|
|
|
|
"reading object");
|
2022-08-16 12:59:32 +00:00
|
|
|
bad = true;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-12-19 10:50:46 +00:00
|
|
|
if (object == nullptr && !is_null &&
|
2022-08-16 12:59:32 +00:00
|
|
|
(!((state == st_start) || (state == st_stop) ||
|
|
|
|
(state == st_eof)))) {
|
|
|
|
throw std::logic_error("QPDFObjectHandle::parseInternal: "
|
|
|
|
"unexpected uninitialized object");
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bad) {
|
|
|
|
++bad_count;
|
|
|
|
good_count = 0;
|
|
|
|
} else {
|
|
|
|
++good_count;
|
|
|
|
if (good_count > 3) {
|
|
|
|
bad_count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bad_count > 5) {
|
|
|
|
// We had too many consecutive errors without enough
|
|
|
|
// intervening successful objects. Give up.
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("too many errors; giving up on reading object");
|
2022-08-16 12:59:32 +00:00
|
|
|
state = st_top;
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case st_eof:
|
|
|
|
if (state_stack.size() > 1) {
|
2022-08-16 13:40:14 +00:00
|
|
|
warn("parse error while reading object");
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
done = true;
|
|
|
|
// In content stream mode, leave object uninitialized to
|
|
|
|
// indicate EOF
|
|
|
|
if (!content_stream) {
|
2022-08-30 12:32:54 +00:00
|
|
|
is_null = true;
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case st_dictionary:
|
|
|
|
case st_array:
|
2023-03-26 19:02:49 +00:00
|
|
|
if (is_null) {
|
|
|
|
object = null_oh;
|
|
|
|
// No need to set description for direct nulls - they probably
|
|
|
|
// will become implicit.
|
|
|
|
} else if (!indirect_ref) {
|
2022-12-16 18:08:56 +00:00
|
|
|
setDescription(object, input->getLastOffset());
|
2022-08-30 12:07:48 +00:00
|
|
|
}
|
2022-08-16 12:59:32 +00:00
|
|
|
set_offset = true;
|
2022-12-19 14:52:32 +00:00
|
|
|
olist.push_back(object);
|
2022-08-16 12:59:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case st_top:
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case st_start:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case st_stop:
|
2022-08-30 11:53:19 +00:00
|
|
|
if ((state_stack.size() < 2) || (stack.size() < 2)) {
|
2022-08-16 12:59:32 +00:00
|
|
|
throw std::logic_error(
|
|
|
|
"QPDFObjectHandle::parseInternal: st_stop encountered"
|
|
|
|
" with insufficient elements in stack");
|
|
|
|
}
|
|
|
|
parser_state_e old_state = state_stack.back();
|
|
|
|
state_stack.pop_back();
|
|
|
|
if (old_state == st_array) {
|
2023-03-26 19:02:49 +00:00
|
|
|
object = QPDF_Array::create(
|
|
|
|
std::move(olist), frame.null_count > 100);
|
2022-12-16 18:08:56 +00:00
|
|
|
setDescription(object, offset - 1);
|
2022-08-30 10:32:43 +00:00
|
|
|
// The `offset` points to the next of "[". Set the rewind
|
|
|
|
// offset to point to the beginning of "[". This has been
|
|
|
|
// explicitly tested with whitespace surrounding the array start
|
|
|
|
// delimiter. getLastOffset points to the array end token and
|
2022-08-16 12:59:32 +00:00
|
|
|
// therefore can't be used here.
|
|
|
|
set_offset = true;
|
|
|
|
} else if (old_state == st_dictionary) {
|
2022-08-30 10:32:43 +00:00
|
|
|
// Convert list to map. Alternating elements are keys. Attempt
|
|
|
|
// to recover more or less gracefully from invalid dictionaries.
|
2022-08-16 12:59:32 +00:00
|
|
|
std::set<std::string> names;
|
2022-12-19 14:52:32 +00:00
|
|
|
for (auto& obj: olist) {
|
|
|
|
if (obj) {
|
|
|
|
if (obj->getTypeCode() == ::ot_name) {
|
|
|
|
names.insert(obj->getStringValue());
|
|
|
|
}
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::string, QPDFObjectHandle> dict;
|
|
|
|
int next_fake_key = 1;
|
2022-12-20 13:58:19 +00:00
|
|
|
for (auto iter = olist.begin(); iter != olist.end();) {
|
|
|
|
// Calculate key.
|
|
|
|
std::string key;
|
|
|
|
if (*iter && (*iter)->getTypeCode() == ::ot_name) {
|
|
|
|
key = (*iter)->getStringValue();
|
|
|
|
++iter;
|
|
|
|
} else {
|
|
|
|
for (bool found_fake = false; !found_fake;) {
|
|
|
|
key = "/QPDFFake" + std::to_string(next_fake_key++);
|
|
|
|
found_fake = (names.count(key) == 0);
|
2022-08-16 12:59:32 +00:00
|
|
|
QTC::TC(
|
|
|
|
"qpdf",
|
|
|
|
"QPDFParser found fake",
|
|
|
|
(found_fake ? 0 : 1));
|
|
|
|
}
|
|
|
|
warn(
|
2022-08-16 13:40:14 +00:00
|
|
|
offset,
|
|
|
|
"expected dictionary key but found"
|
|
|
|
" non-name object; inserting key " +
|
2022-12-20 13:58:19 +00:00
|
|
|
key);
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
if (dict.count(key) > 0) {
|
|
|
|
QTC::TC("qpdf", "QPDFParser duplicate dict key");
|
|
|
|
warn(
|
2022-08-16 13:40:14 +00:00
|
|
|
offset,
|
|
|
|
"dictionary has duplicated key " + key +
|
|
|
|
"; last occurrence overrides earlier "
|
|
|
|
"ones");
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
2022-12-20 13:58:19 +00:00
|
|
|
|
|
|
|
// Calculate value.
|
|
|
|
std::shared_ptr<QPDFObject> val;
|
|
|
|
if (iter != olist.end()) {
|
2023-03-26 19:02:49 +00:00
|
|
|
val = *iter;
|
2022-12-20 13:58:19 +00:00
|
|
|
++iter;
|
|
|
|
} else {
|
|
|
|
QTC::TC("qpdf", "QPDFParser no val for last key");
|
|
|
|
warn(
|
|
|
|
offset,
|
|
|
|
"dictionary ended prematurely; "
|
|
|
|
"using null as value for last key");
|
|
|
|
val = QPDF_Null::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
dict[std::move(key)] = std::move(val);
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
2022-08-30 11:53:19 +00:00
|
|
|
if (!frame.contents_string.empty() && dict.count("/Type") &&
|
2022-08-16 12:59:32 +00:00
|
|
|
dict["/Type"].isNameAndEquals("/Sig") &&
|
|
|
|
dict.count("/ByteRange") && dict.count("/Contents") &&
|
|
|
|
dict["/Contents"].isString()) {
|
|
|
|
dict["/Contents"] =
|
2022-08-30 11:53:19 +00:00
|
|
|
QPDFObjectHandle::newString(frame.contents_string);
|
|
|
|
dict["/Contents"].setParsedOffset(frame.contents_offset);
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
2022-12-19 19:20:36 +00:00
|
|
|
object = QPDF_Dictionary::create(std::move(dict));
|
2022-12-16 18:08:56 +00:00
|
|
|
setDescription(object, offset - 2);
|
2022-08-30 10:32:43 +00:00
|
|
|
// The `offset` points to the next of "<<". Set the rewind
|
|
|
|
// offset to point to the beginning of "<<". This has been
|
|
|
|
// explicitly tested with whitespace surrounding the dictionary
|
|
|
|
// start delimiter. getLastOffset points to the dictionary end
|
|
|
|
// token and therefore can't be used here.
|
2022-08-16 12:59:32 +00:00
|
|
|
set_offset = true;
|
|
|
|
}
|
2022-08-30 11:53:19 +00:00
|
|
|
stack.pop_back();
|
2022-08-16 12:59:32 +00:00
|
|
|
if (state_stack.back() == st_top) {
|
|
|
|
done = true;
|
|
|
|
} else {
|
2022-12-19 14:52:32 +00:00
|
|
|
stack.back().olist.push_back(object);
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 12:32:54 +00:00
|
|
|
if (is_null) {
|
2022-12-19 10:50:46 +00:00
|
|
|
object = QPDF_Null::create();
|
2022-08-30 12:32:54 +00:00
|
|
|
}
|
2022-08-16 12:59:32 +00:00
|
|
|
if (!set_offset) {
|
2022-12-16 18:08:56 +00:00
|
|
|
setDescription(object, offset);
|
2022-08-16 12:59:32 +00:00
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2022-08-30 05:42:46 +00:00
|
|
|
void
|
2022-12-19 15:16:16 +00:00
|
|
|
QPDFParser::setDescription(
|
|
|
|
std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset)
|
2022-08-30 05:42:46 +00:00
|
|
|
{
|
2022-12-19 15:16:16 +00:00
|
|
|
if (obj) {
|
2022-12-16 18:08:56 +00:00
|
|
|
obj->setDescription(context, description, parsed_offset);
|
2022-12-15 09:56:46 +00:00
|
|
|
}
|
2022-08-30 05:42:46 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 12:59:32 +00:00
|
|
|
void
|
2022-12-19 15:26:21 +00:00
|
|
|
QPDFParser::warn(QPDFExc const& e) const
|
2022-08-16 12:59:32 +00:00
|
|
|
{
|
|
|
|
// If parsing on behalf of a QPDF object and want to give a
|
|
|
|
// warning, we can warn through the object. If parsing for some
|
|
|
|
// other reason, such as an explicit creation of an object from a
|
|
|
|
// string, then just throw the exception.
|
2022-12-19 15:26:21 +00:00
|
|
|
if (context) {
|
|
|
|
context->warn(e);
|
2022-08-16 12:59:32 +00:00
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2022-08-16 13:40:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const
|
|
|
|
{
|
2022-12-19 15:26:21 +00:00
|
|
|
warn(QPDFExc(
|
|
|
|
qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg));
|
2022-08-16 13:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDFParser::warn(std::string const& msg) const
|
|
|
|
{
|
|
|
|
warn(input->getLastOffset(), msg);
|
|
|
|
}
|