diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index fa96c4b0..68fc78f8 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -1429,21 +1429,20 @@ class QPDFObjectHandle private: static QPDFObjectHandle - newIndirect(QPDF* qpdf, int objid, int generation) + newIndirect(QPDF* qpdf, QPDFObjGen const& og) { - return QPDFObjectHandle::newIndirect(qpdf, objid, generation); + return QPDFObjectHandle::newIndirect(qpdf, og); } static QPDFObjectHandle newStream( QPDF* qpdf, - int objid, - int generation, + QPDFObjGen const& og, QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length) { return QPDFObjectHandle::newStream( - qpdf, objid, generation, stream_dict, offset, length); + qpdf, og, stream_dict, offset, length); } // Reserve an object with a specific ID static QPDFObjectHandle @@ -1563,11 +1562,10 @@ class QPDFObjectHandle }; // Private object factory methods - static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation); + static QPDFObjectHandle newIndirect(QPDF*, QPDFObjGen const& og); static QPDFObjectHandle newStream( QPDF* qpdf, - int objid, - int generation, + QPDFObjGen const& og, QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 5397da4f..97303471 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -1404,9 +1404,8 @@ QPDF::fixDanglingReferences(bool force) // For each non-scalar item to process, put it in the queue. std::list queue; queue.push_back(this->m->trailer); - for (auto const& iter: to_process) { - QPDFObjectHandle obj = QPDFObjectHandle::Factory::newIndirect( - this, iter.getObj(), iter.getGen()); + for (auto const& og: to_process) { + QPDFObjectHandle obj = QPDFObjectHandle::Factory::newIndirect(this, og); if (obj.isDictionary() || obj.isArray()) { queue.push_back(obj); } else if (obj.isStream()) { @@ -1472,10 +1471,7 @@ QPDF::getAllObjects() std::vector result; for (auto const& iter: this->m->obj_cache) { QPDFObjGen const& og = iter.first; - result.push_back( - // line-break - QPDFObjectHandle::Factory::newIndirect( - this, og.getObj(), og.getGen())); + result.push_back(QPDFObjectHandle::Factory::newIndirect(this, og)); } return result; } @@ -1662,7 +1658,11 @@ QPDF::readObject( } } object = QPDFObjectHandle::Factory::newStream( - this, objid, generation, object, stream_offset, length); + this, + QPDFObjGen(objid, generation), + object, + stream_offset, + length); } else { input->seek(cur_offset, SEEK_SET); } @@ -2159,8 +2159,7 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh) QPDFObjGen next(max_objid + 1, 0); this->m->obj_cache[next] = ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); - return QPDFObjectHandle::Factory::newIndirect( - this, next.getObj(), next.getGen()); + return QPDFObjectHandle::Factory::newIndirect(this, next); } QPDFObjectHandle @@ -2178,19 +2177,19 @@ QPDFObjectHandle QPDF::reserveStream(int objid, int gen) { return QPDFObjectHandle::Factory::newStream( - this, objid, gen, QPDFObjectHandle::newDictionary(), 0, 0); + this, QPDFObjGen(objid, gen), QPDFObjectHandle::newDictionary(), 0, 0); } QPDFObjectHandle QPDF::getObjectByObjGen(QPDFObjGen const& og) { - return getObjectByID(og.getObj(), og.getGen()); + return QPDFObjectHandle::Factory::newIndirect(this, og); } QPDFObjectHandle QPDF::getObjectByID(int objid, int generation) { - return QPDFObjectHandle::Factory::newIndirect(this, objid, generation); + return getObjectByObjGen(QPDFObjGen(objid, generation)); } void diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 880e44bd..779a61ed 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -2180,8 +2180,9 @@ QPDFObjectHandle::parseInternal( // Try to resolve indirect objects object = newIndirect( context, - olist.at(olist.size() - 2).getIntValueAsInt(), - olist.at(olist.size() - 1).getIntValueAsInt()); + QPDFObjGen( + olist.at(olist.size() - 2).getIntValueAsInt(), + olist.at(olist.size() - 1).getIntValueAsInt())); olist.remove_last(); olist.remove_last(); } else if ((value == "endobj") && (state == st_top)) { @@ -2469,9 +2470,9 @@ QPDFObjectHandle::setParsedOffset(qpdf_offset_t offset) } QPDFObjectHandle -QPDFObjectHandle::newIndirect(QPDF* qpdf, int objid, int generation) +QPDFObjectHandle::newIndirect(QPDF* qpdf, QPDFObjGen const& og) { - if (objid == 0) { + if (!og.isIndirect()) { // Special case: QPDF uses objid 0 as a sentinel for direct // objects, and the PDF specification doesn't allow for object // 0. Treat indirect references to object 0 as null so that we @@ -2480,7 +2481,7 @@ QPDFObjectHandle::newIndirect(QPDF* qpdf, int objid, int generation) return newNull(); } - return QPDFObjectHandle(qpdf, QPDFObjGen(objid, generation)); + return QPDFObjectHandle(qpdf, og); } QPDFObjectHandle @@ -2628,14 +2629,13 @@ QPDFObjectHandle::newDictionary( QPDFObjectHandle QPDFObjectHandle::newStream( QPDF* qpdf, - int objid, - int generation, + QPDFObjGen const& og, QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length) { QPDFObjectHandle result = QPDFObjectHandle(QPDF_Stream::create( - qpdf, objid, generation, stream_dict, offset, length)); + qpdf, og.getObj(), og.getGen(), stream_dict, offset, length)); if (offset) { result.setParsedOffset(offset); } @@ -2683,8 +2683,7 @@ QPDFObjectHandle::newReserved(QPDF* qpdf) // Reserve a spot for this object by assigning it an object // number, but then return an unresolved handle to the object. QPDFObjectHandle reserved = qpdf->makeIndirectObject(makeReserved()); - QPDFObjectHandle result = - newIndirect(qpdf, reserved.getObjectID(), reserved.getGeneration()); + QPDFObjectHandle result = newIndirect(qpdf, reserved.getObjGen()); result.reserved = true; return result; } diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index b92ba5f2..cb4d721f 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -138,7 +138,7 @@ QPDF::isLinearized() } QPDFObjectHandle candidate = - QPDFObjectHandle::Factory::newIndirect(this, lindict_obj, 0); + QPDFObjectHandle::Factory::newIndirect(this, QPDFObjGen(lindict_obj)); if (!candidate.isDictionary()) { return false; }