aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/qpdf/QPDF.hh2
-rw-r--r--include/qpdf/QPDFObject.hh6
-rw-r--r--libqpdf/QPDF.cc23
-rw-r--r--libqpdf/QPDFObjectHandle.cc2
4 files changed, 25 insertions, 8 deletions
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh
index 701c5e55..ee265cec 100644
--- a/include/qpdf/QPDF.hh
+++ b/include/qpdf/QPDF.hh
@@ -1175,6 +1175,8 @@ class QPDF
QPDFObjectHandle reserveStream(QPDFObjGen const& og);
QPDFObjectHandle
newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
+ bool isCached(QPDFObjGen const& og);
+ bool isUnresolved(QPDFObjGen const& og);
// Calls finish() on the pipeline when done but does not delete it
bool pipeStreamData(
diff --git a/include/qpdf/QPDFObject.hh b/include/qpdf/QPDFObject.hh
index a1930168..198488dd 100644
--- a/include/qpdf/QPDFObject.hh
+++ b/include/qpdf/QPDFObject.hh
@@ -134,7 +134,11 @@ class QPDFObject
value = o->value;
o->value = v;
}
-
+ bool
+ isUnresolved()
+ {
+ return value->type_code == ::ot_unresolved;
+ }
template <typename T>
T*
as()
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 000dab5d..d877c14a 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -1425,8 +1425,7 @@ QPDF::fixDanglingReferences(bool force)
for (auto sub: to_check) {
if (sub.isIndirect()) {
if (sub.getOwningQPDF() == this) {
- QPDFObjGen og(sub.getObjGen());
- if (this->m->obj_cache.count(og) == 0) {
+ if (!isCached(sub.getObjGen())) {
QTC::TC("qpdf", "QPDF detected dangling ref");
queue.push_back(sub);
}
@@ -1886,7 +1885,7 @@ QPDF::readObjectAtOffset(
"expected endobj");
}
- if (!this->m->obj_cache.count(og)) {
+ if (!isCached(og)) {
// Store the object in the cache here so it gets cached
// whether we first know the offset or whether we first know
// the object ID and generation (in which we case we would get
@@ -1947,7 +1946,7 @@ QPDF::resolve(QPDFObjGen const& og)
}
ResolveRecorder rr(this, og);
- if ((!this->m->obj_cache.count(og)) && this->m->xref_table.count(og)) {
+ if ((!isCached(og)) && this->m->xref_table.count(og)) {
QPDFXRefEntry const& entry = this->m->xref_table[og];
try {
switch (entry.getType()) {
@@ -1985,7 +1984,7 @@ QPDF::resolve(QPDFObjGen const& og)
": error reading object: " + e.what()));
}
}
- if (this->m->obj_cache.count(og) == 0) {
+ if (!isCached(og)) {
// PDF spec says unknown objects resolve to the null object.
QTC::TC("qpdf", "QPDF resolve failure to null");
QPDFObjectHandle oh = QPDFObjectHandle::newNull();
@@ -2112,6 +2111,18 @@ QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj)
return QPDFObjectHandle::Factory::newIndirect(this, og, obj);
}
+bool
+QPDF::isCached(QPDFObjGen const& og)
+{
+ return m->obj_cache.count(og) != 0;
+}
+
+bool
+QPDF::isUnresolved(QPDFObjGen const& og)
+{
+ return !isCached(og) || m->obj_cache[og].object->isUnresolved();
+}
+
QPDFObjectHandle
QPDF::makeIndirectObject(QPDFObjectHandle oh)
{
@@ -2129,7 +2140,7 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh)
QPDFObjectHandle
QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
{
- if ((!m->obj_cache.count(og)) && (!m->xref_table.count(og))) {
+ if (!isCached(og) && !m->xref_table.count(og)) {
resolve(og);
m->obj_cache[og].object = QPDF_Reserved::create();
return newIndirect(og, m->obj_cache[og].object);
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index c8611e07..aae06529 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -2609,7 +2609,7 @@ QPDFObjectHandle::dereference()
if (!isInitialized()) {
return false;
}
- if (this->obj->getTypeCode() == QPDFObject::ot_unresolved) {
+ if (this->obj->isUnresolved()) {
this->obj = QPDF::Resolver::resolve(this->qpdf, getObjGen());
}
return true;