Commit a3037ca440e2a7cf9b5d377c932f2d322f31dace

Authored by Jay Berkenbilt
Committed by GitHub
2 parents 80950066 1553868c

Merge pull request #739 from m-holger/getobject

Add QPDF::getObject to replace getObjectByObjGen and getObjectByID
include/qpdf/QPDF.hh
... ... @@ -385,6 +385,10 @@ class QPDF
385 385 // Retrieve an object by object ID and generation. Returns an
386 386 // indirect reference to it.
387 387 QPDF_DLL
  388 + QPDFObjectHandle getObject(QPDFObjGen const&);
  389 + QPDF_DLL
  390 + QPDFObjectHandle getObject(int objid, int generation);
  391 + QPDF_DLL
388 392 QPDFObjectHandle getObjectByObjGen(QPDFObjGen const&);
389 393 QPDF_DLL
390 394 QPDFObjectHandle getObjectByID(int objid, int generation);
... ...
libqpdf/QPDF.cc
... ... @@ -2148,7 +2148,7 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
2148 2148 resolve(og);
2149 2149 replaceObject(og, QPDFObjectHandle::Factory::makeReserved());
2150 2150 }
2151   - return getObjectByObjGen(og);
  2151 + return getObject(og);
2152 2152 }
2153 2153  
2154 2154 QPDFObjectHandle
... ... @@ -2159,15 +2159,27 @@ QPDF::reserveStream(QPDFObjGen const& og)
2159 2159 }
2160 2160  
2161 2161 QPDFObjectHandle
2162   -QPDF::getObjectByObjGen(QPDFObjGen const& og)
  2162 +QPDF::getObject(QPDFObjGen const& og)
2163 2163 {
2164 2164 return QPDFObjectHandle::Factory::newIndirect(this, og);
2165 2165 }
2166 2166  
2167 2167 QPDFObjectHandle
  2168 +QPDF::getObject(int objid, int generation)
  2169 +{
  2170 + return getObject(QPDFObjGen(objid, generation));
  2171 +}
  2172 +
  2173 +QPDFObjectHandle
  2174 +QPDF::getObjectByObjGen(QPDFObjGen const& og)
  2175 +{
  2176 + return getObject(og);
  2177 +}
  2178 +
  2179 +QPDFObjectHandle
2168 2180 QPDF::getObjectByID(int objid, int generation)
2169 2181 {
2170   - return getObjectByObjGen(QPDFObjGen(objid, generation));
  2182 + return getObject(QPDFObjGen(objid, generation));
2171 2183 }
2172 2184  
2173 2185 void
... ...
libqpdf/QPDFAcroFormDocumentHelper.cc
... ... @@ -183,7 +183,7 @@ QPDFAcroFormDocumentHelper::getFormFields()
183 183 analyze();
184 184 std::vector<QPDFFormFieldObjectHelper> result;
185 185 for (auto const& iter: this->m->field_to_annotations) {
186   - result.push_back(this->qpdf.getObjectByObjGen(iter.first));
  186 + result.push_back(this->qpdf.getObject(iter.first));
187 187 }
188 188 return result;
189 189 }
... ...
libqpdf/QPDFWriter.cc
... ... @@ -1897,7 +1897,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1897 1897 // pass 1.
1898 1898 indicateProgress(true, false);
1899 1899 }
1900   - QPDFObjectHandle obj_to_write = this->m->pdf.getObjectByObjGen(obj);
  1900 + QPDFObjectHandle obj_to_write = this->m->pdf.getObject(obj);
1901 1901 if (obj_to_write.isStream()) {
1902 1902 // This condition occurred in a fuzz input. Ideally we
1903 1903 // should block it at at parse time, but it's not
... ...
libqpdf/QPDF_json.cc
... ... @@ -394,7 +394,7 @@ QPDF::JSONReactor::replaceObject(
394 394 auto og = to_replace.getObjGen();
395 395 this->reserved.erase(og);
396 396 this->pdf.replaceObject(og, replacement);
397   - auto oh = pdf.getObjectByObjGen(og);
  397 + auto oh = pdf.getObject(og);
398 398 setObjectDescription(oh, value);
399 399 }
400 400  
... ...
libqpdf/QPDF_linearization.cc
... ... @@ -706,7 +706,7 @@ QPDF::getUncompressedObject(
706 706 return obj;
707 707 } else {
708 708 int repl = (*(object_stream_data.find(obj.getObjectID()))).second;
709   - return getObjectByObjGen(QPDFObjGen(repl, 0));
  709 + return getObject(repl, 0);
710 710 }
711 711 }
712 712  
... ... @@ -1381,9 +1381,9 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1381 1381 stopOnError("found other than one root while"
1382 1382 " calculating linearization data");
1383 1383 }
1384   - this->m->part4.push_back(getObjectByObjGen(*(lc_root.begin())));
  1384 + this->m->part4.push_back(getObject(*(lc_root.begin())));
1385 1385 for (auto const& og: lc_open_document) {
1386   - this->m->part4.push_back(getObjectByObjGen(og));
  1386 + this->m->part4.push_back(getObject(og));
1387 1387 }
1388 1388  
1389 1389 // Part 6: first page objects. Note: implementation note 124
... ... @@ -1412,11 +1412,11 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1412 1412 // hint tables.
1413 1413  
1414 1414 for (auto const& og: lc_first_page_private) {
1415   - this->m->part6.push_back(getObjectByObjGen(og));
  1415 + this->m->part6.push_back(getObject(og));
1416 1416 }
1417 1417  
1418 1418 for (auto const& og: lc_first_page_shared) {
1419   - this->m->part6.push_back(getObjectByObjGen(og));
  1419 + this->m->part6.push_back(getObject(og));
1420 1420 }
1421 1421  
1422 1422 // Place the outline dictionary if it goes in the first page section.
... ... @@ -1462,7 +1462,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1462 1462 for (auto const& og: this->m->obj_user_to_objects[ou]) {
1463 1463 if (lc_other_page_private.count(og)) {
1464 1464 lc_other_page_private.erase(og);
1465   - this->m->part7.push_back(getObjectByObjGen(og));
  1465 + this->m->part7.push_back(getObject(og));
1466 1466 ++this->m->c_page_offset_data.entries.at(i).nobjects;
1467 1467 }
1468 1468 }
... ... @@ -1479,7 +1479,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1479 1479  
1480 1480 // Order is unimportant.
1481 1481 for (auto const& og: lc_other_page_shared) {
1482   - this->m->part8.push_back(getObjectByObjGen(og));
  1482 + this->m->part8.push_back(getObject(og));
1483 1483 }
1484 1484  
1485 1485 // Part 9: other objects
... ... @@ -1501,7 +1501,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1501 1501 for (auto const& og: pages_ogs) {
1502 1502 if (lc_other.count(og)) {
1503 1503 lc_other.erase(og);
1504   - this->m->part9.push_back(getObjectByObjGen(og));
  1504 + this->m->part9.push_back(getObject(og));
1505 1505 }
1506 1506 }
1507 1507  
... ... @@ -1531,7 +1531,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1531 1531 for (auto const& og: ogs) {
1532 1532 if (lc_thumbnail_private.count(og)) {
1533 1533 lc_thumbnail_private.erase(og);
1534   - this->m->part9.push_back(getObjectByObjGen(og));
  1534 + this->m->part9.push_back(getObject(og));
1535 1535 }
1536 1536 }
1537 1537 }
... ... @@ -1544,7 +1544,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1544 1544  
1545 1545 // Place shared thumbnail objects
1546 1546 for (auto const& og: lc_thumbnail_shared) {
1547   - this->m->part9.push_back(getObjectByObjGen(og));
  1547 + this->m->part9.push_back(getObject(og));
1548 1548 }
1549 1549  
1550 1550 // Place outlines unless in first page
... ... @@ -1554,7 +1554,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1554 1554  
1555 1555 // Place all remaining objects
1556 1556 for (auto const& og: lc_other) {
1557   - this->m->part9.push_back(getObjectByObjGen(og));
  1557 + this->m->part9.push_back(getObject(og));
1558 1558 }
1559 1559  
1560 1560 // Make sure we got everything exactly once.
... ... @@ -1656,7 +1656,7 @@ QPDF::pushOutlinesToPart(
1656 1656 lc_outlines.erase(outlines_og);
1657 1657 part.push_back(outlines);
1658 1658 for (auto const& og: lc_outlines) {
1659   - part.push_back(getObjectByObjGen(og));
  1659 + part.push_back(getObject(og));
1660 1660 ++this->m->c_outline_data.nobjects;
1661 1661 }
1662 1662 }
... ...