2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-08 06:15:23 +00:00

In QPDFParser constructor add add parameter parse_pdf

Prepare for treating indirect references differently depending on whether
we are parsing a PDF file (in which case reference to objects not in the
xref table are null even if they are in the object cache) or whether parse
from user code (in which case an indirect reference can refer to a user
created object).
This commit is contained in:
m-holger 2024-07-25 10:22:35 +01:00
parent 77d1a0cf24
commit 87ee8ad071
6 changed files with 16 additions and 11 deletions

View File

@ -1462,7 +1462,8 @@ QPDF::readTrailer()
{ {
qpdf_offset_t offset = m->file->tell(); qpdf_offset_t offset = m->file->tell();
bool empty = false; bool empty = false;
auto object = QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this).parse(empty, false); auto object =
QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false);
if (empty) { if (empty) {
// Nothing in the PDF spec appears to allow empty objects, but they have been encountered in // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
// actual PDF files and Adobe Reader appears to ignore them. // actual PDF files and Adobe Reader appears to ignore them.
@ -1484,8 +1485,9 @@ QPDF::readObject(std::string const& description, QPDFObjGen og)
StringDecrypter decrypter{this, og}; StringDecrypter decrypter{this, og};
StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr; StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr;
auto object = QPDFParser(m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this) auto object =
.parse(empty, false); QPDFParser(m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true)
.parse(empty, false);
if (empty) { if (empty) {
// Nothing in the PDF spec appears to allow empty objects, but they have been encountered in // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
// actual PDF files and Adobe Reader appears to ignore them. // actual PDF files and Adobe Reader appears to ignore them.
@ -1604,7 +1606,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj)
m->last_object_description += " 0"; m->last_object_description += " 0";
bool empty = false; bool empty = false;
auto object = QPDFParser(input, m->last_object_description, m->tokenizer, nullptr, this) auto object = QPDFParser(input, m->last_object_description, m->tokenizer, nullptr, this, true)
.parse(empty, false); .parse(empty, false);
if (empty) { if (empty) {
// Nothing in the PDF spec appears to allow empty objects, but they have been encountered in // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in

View File

@ -2146,7 +2146,8 @@ QPDFObjectHandle::parseContentStream_data(
tokenizer.readToken(input, "content", true); tokenizer.readToken(input, "content", true);
qpdf_offset_t offset = input->getLastOffset(); qpdf_offset_t offset = input->getLastOffset();
input->seek(offset, SEEK_SET); input->seek(offset, SEEK_SET);
auto obj = QPDFParser(input, "content", tokenizer, nullptr, context).parse(empty, true); auto obj =
QPDFParser(input, "content", tokenizer, nullptr, context, false).parse(empty, true);
if (!obj.isInitialized()) { if (!obj.isInitialized()) {
// EOF // EOF
break; break;
@ -2205,7 +2206,8 @@ QPDFObjectHandle::parse(
StringDecrypter* decrypter, StringDecrypter* decrypter,
QPDF* context) QPDF* context)
{ {
return QPDFParser(input, object_description, tokenizer, decrypter, context).parse(empty, false); return QPDFParser(input, object_description, tokenizer, decrypter, context, false)
.parse(empty, false);
} }
#ifndef QPDF_FUTURE #ifndef QPDF_FUTURE

View File

@ -71,7 +71,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
m->dest_dict = qpdf.getRoot().getKey("/Dests"); m->dest_dict = qpdf.getRoot().getKey("/Dests");
} }
QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest"); QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest");
result= m->dest_dict.getKeyIfDict(name.getName()); result = m->dest_dict.getKeyIfDict(name.getName());
} else if (name.isString()) { } else if (name.isString()) {
if (!m->names_dest) { if (!m->names_dest) {
auto dests = qpdf.getRoot().getKey("/Names").getKeyIfDict("/Dests"); auto dests = qpdf.getRoot().getKey("/Names").getKeyIfDict("/Dests");

View File

@ -272,10 +272,10 @@ class QPDF::JSONReactor: public JSON::Reactor
struct StackFrame struct StackFrame
{ {
StackFrame(state_e state) : StackFrame(state_e state) :
state(state){}; state(state) {};
StackFrame(state_e state, QPDFObjectHandle&& object) : StackFrame(state_e state, QPDFObjectHandle&& object) :
state(state), state(state),
object(object){}; object(object) {};
state_e state; state_e state;
QPDFObjectHandle object; QPDFObjectHandle object;
}; };

View File

@ -16,7 +16,8 @@ class QPDFParser
std::string const& object_description, std::string const& object_description,
QPDFTokenizer& tokenizer, QPDFTokenizer& tokenizer,
QPDFObjectHandle::StringDecrypter* decrypter, QPDFObjectHandle::StringDecrypter* decrypter,
QPDF* context) : QPDF* context,
bool parse_pdf) :
input(input), input(input),
object_description(object_description), object_description(object_description),
tokenizer(tokenizer), tokenizer(tokenizer),

View File

@ -16,7 +16,7 @@ struct _qpdf_data
_qpdf_data() = default; _qpdf_data() = default;
_qpdf_data(std::unique_ptr<QPDF>&& qpdf) : _qpdf_data(std::unique_ptr<QPDF>&& qpdf) :
qpdf(std::move(qpdf)){}; qpdf(std::move(qpdf)) {};
~_qpdf_data() = default; ~_qpdf_data() = default;