Commit 87ee8ad0710ccc8e7712487caaf707032974dca1

Authored by m-holger
1 parent 77d1a0cf

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).
libqpdf/QPDF.cc
@@ -1462,7 +1462,8 @@ QPDF::readTrailer() @@ -1462,7 +1462,8 @@ QPDF::readTrailer()
1462 { 1462 {
1463 qpdf_offset_t offset = m->file->tell(); 1463 qpdf_offset_t offset = m->file->tell();
1464 bool empty = false; 1464 bool empty = false;
1465 - auto object = QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this).parse(empty, false); 1465 + auto object =
  1466 + QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false);
1466 if (empty) { 1467 if (empty) {
1467 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in 1468 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
1468 // actual PDF files and Adobe Reader appears to ignore them. 1469 // actual PDF files and Adobe Reader appears to ignore them.
@@ -1484,8 +1485,9 @@ QPDF::readObject(std::string const& description, QPDFObjGen og) @@ -1484,8 +1485,9 @@ QPDF::readObject(std::string const& description, QPDFObjGen og)
1484 1485
1485 StringDecrypter decrypter{this, og}; 1486 StringDecrypter decrypter{this, og};
1486 StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr; 1487 StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr;
1487 - auto object = QPDFParser(m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this)  
1488 - .parse(empty, false); 1488 + auto object =
  1489 + QPDFParser(m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true)
  1490 + .parse(empty, false);
1489 if (empty) { 1491 if (empty) {
1490 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in 1492 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
1491 // actual PDF files and Adobe Reader appears to ignore them. 1493 // actual PDF files and Adobe Reader appears to ignore them.
@@ -1604,7 +1606,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj) @@ -1604,7 +1606,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj)
1604 m->last_object_description += " 0"; 1606 m->last_object_description += " 0";
1605 1607
1606 bool empty = false; 1608 bool empty = false;
1607 - auto object = QPDFParser(input, m->last_object_description, m->tokenizer, nullptr, this) 1609 + auto object = QPDFParser(input, m->last_object_description, m->tokenizer, nullptr, this, true)
1608 .parse(empty, false); 1610 .parse(empty, false);
1609 if (empty) { 1611 if (empty) {
1610 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in 1612 // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
libqpdf/QPDFObjectHandle.cc
@@ -2146,7 +2146,8 @@ QPDFObjectHandle::parseContentStream_data( @@ -2146,7 +2146,8 @@ QPDFObjectHandle::parseContentStream_data(
2146 tokenizer.readToken(input, "content", true); 2146 tokenizer.readToken(input, "content", true);
2147 qpdf_offset_t offset = input->getLastOffset(); 2147 qpdf_offset_t offset = input->getLastOffset();
2148 input->seek(offset, SEEK_SET); 2148 input->seek(offset, SEEK_SET);
2149 - auto obj = QPDFParser(input, "content", tokenizer, nullptr, context).parse(empty, true); 2149 + auto obj =
  2150 + QPDFParser(input, "content", tokenizer, nullptr, context, false).parse(empty, true);
2150 if (!obj.isInitialized()) { 2151 if (!obj.isInitialized()) {
2151 // EOF 2152 // EOF
2152 break; 2153 break;
@@ -2205,7 +2206,8 @@ QPDFObjectHandle::parse( @@ -2205,7 +2206,8 @@ QPDFObjectHandle::parse(
2205 StringDecrypter* decrypter, 2206 StringDecrypter* decrypter,
2206 QPDF* context) 2207 QPDF* context)
2207 { 2208 {
2208 - return QPDFParser(input, object_description, tokenizer, decrypter, context).parse(empty, false); 2209 + return QPDFParser(input, object_description, tokenizer, decrypter, context, false)
  2210 + .parse(empty, false);
2209 } 2211 }
2210 2212
2211 #ifndef QPDF_FUTURE 2213 #ifndef QPDF_FUTURE
libqpdf/QPDFOutlineDocumentHelper.cc
@@ -71,7 +71,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name) @@ -71,7 +71,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
71 m->dest_dict = qpdf.getRoot().getKey("/Dests"); 71 m->dest_dict = qpdf.getRoot().getKey("/Dests");
72 } 72 }
73 QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest"); 73 QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest");
74 - result= m->dest_dict.getKeyIfDict(name.getName()); 74 + result = m->dest_dict.getKeyIfDict(name.getName());
75 } else if (name.isString()) { 75 } else if (name.isString()) {
76 if (!m->names_dest) { 76 if (!m->names_dest) {
77 auto dests = qpdf.getRoot().getKey("/Names").getKeyIfDict("/Dests"); 77 auto dests = qpdf.getRoot().getKey("/Names").getKeyIfDict("/Dests");
libqpdf/QPDF_json.cc
@@ -272,10 +272,10 @@ class QPDF::JSONReactor: public JSON::Reactor @@ -272,10 +272,10 @@ class QPDF::JSONReactor: public JSON::Reactor
272 struct StackFrame 272 struct StackFrame
273 { 273 {
274 StackFrame(state_e state) : 274 StackFrame(state_e state) :
275 - state(state){}; 275 + state(state) {};
276 StackFrame(state_e state, QPDFObjectHandle&& object) : 276 StackFrame(state_e state, QPDFObjectHandle&& object) :
277 state(state), 277 state(state),
278 - object(object){}; 278 + object(object) {};
279 state_e state; 279 state_e state;
280 QPDFObjectHandle object; 280 QPDFObjectHandle object;
281 }; 281 };
libqpdf/qpdf/QPDFParser.hh
@@ -16,7 +16,8 @@ class QPDFParser @@ -16,7 +16,8 @@ class QPDFParser
16 std::string const& object_description, 16 std::string const& object_description,
17 QPDFTokenizer& tokenizer, 17 QPDFTokenizer& tokenizer,
18 QPDFObjectHandle::StringDecrypter* decrypter, 18 QPDFObjectHandle::StringDecrypter* decrypter,
19 - QPDF* context) : 19 + QPDF* context,
  20 + bool parse_pdf) :
20 input(input), 21 input(input),
21 object_description(object_description), 22 object_description(object_description),
22 tokenizer(tokenizer), 23 tokenizer(tokenizer),
libqpdf/qpdf/qpdf-c_impl.hh
@@ -16,7 +16,7 @@ struct _qpdf_data @@ -16,7 +16,7 @@ struct _qpdf_data
16 _qpdf_data() = default; 16 _qpdf_data() = default;
17 17
18 _qpdf_data(std::unique_ptr<QPDF>&& qpdf) : 18 _qpdf_data(std::unique_ptr<QPDF>&& qpdf) :
19 - qpdf(std::move(qpdf)){}; 19 + qpdf(std::move(qpdf)) {};
20 20
21 ~_qpdf_data() = default; 21 ~_qpdf_data() = default;
22 22