Commit e9c1637353fc3d063ae06bf98dd200e245ef9ff4

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 97f737a5

Add private method QPDFObjectHandle::getObjGenAsStr

Also, use methods to access objid and generation.
include/qpdf/QPDFObjectHandle.hh
... ... @@ -1581,6 +1581,7 @@ class QPDFObjectHandle
1581 1581 bool stop_at_streams);
1582 1582 void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only);
1583 1583 void releaseResolved();
  1584 + std::string getObjGenAsStr() const;
1584 1585 static void setObjectDescriptionFromInput(
1585 1586 QPDFObjectHandle,
1586 1587 QPDF*,
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -338,7 +338,7 @@ QPDFObjectHandle::isDirectNull() const
338 338 // Don't call dereference() -- this is a const method, and we know
339 339 // objid == 0, so there's nothing to resolve.
340 340 return (
341   - this->initialized && (this->objid == 0) &&
  341 + this->initialized && (getObjectID() == 0) &&
342 342 QPDFObjectTypeAccessor<QPDF_Null>::check(obj.get()));
343 343 }
344 344  
... ... @@ -490,7 +490,7 @@ QPDFObjectHandle::isIndirect()
490 490 if (!this->initialized) {
491 491 return false;
492 492 }
493   - return (this->objid != 0);
  493 + return (getObjectID() != 0);
494 494 }
495 495  
496 496 bool
... ... @@ -1549,6 +1549,13 @@ QPDFObjectHandle::getObjGen() const
1549 1549 return QPDFObjGen(this->objid, this->generation);
1550 1550 }
1551 1551  
  1552 +std::string
  1553 +QPDFObjectHandle::getObjGenAsStr() const
  1554 +{
  1555 + return QUtil::int_to_string(this->objid) + " " +
  1556 + QUtil::int_to_string(this->generation);
  1557 +}
  1558 +
1552 1559 int
1553 1560 QPDFObjectHandle::getObjectID() const
1554 1561 {
... ... @@ -1608,14 +1615,12 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
1608 1615  
1609 1616 bool first = true;
1610 1617 for (auto const& item: result) {
1611   - std::string og = QUtil::int_to_string(item.getObjectID()) + " " +
1612   - QUtil::int_to_string(item.getGeneration());
1613 1618 if (first) {
1614 1619 first = false;
1615 1620 } else {
1616 1621 all_description += ",";
1617 1622 }
1618   - all_description += " stream " + og;
  1623 + all_description += " stream " + item.getObjGenAsStr();
1619 1624 }
1620 1625  
1621 1626 return result;
... ... @@ -1624,9 +1629,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
1624 1629 std::vector<QPDFObjectHandle>
1625 1630 QPDFObjectHandle::getPageContents()
1626 1631 {
1627   - std::string description = "page object " +
1628   - QUtil::int_to_string(this->objid) + " " +
1629   - QUtil::int_to_string(this->generation);
  1632 + std::string description = "page object " + getObjGenAsStr();
1630 1633 std::string all_description;
1631 1634 return this->getKey("/Contents")
1632 1635 .arrayOrStreamToStreamArray(description, all_description);
... ... @@ -1735,8 +1738,7 @@ QPDFObjectHandle::unparse()
1735 1738 {
1736 1739 std::string result;
1737 1740 if (this->isIndirect()) {
1738   - result = QUtil::int_to_string(this->objid) + " " +
1739   - QUtil::int_to_string(this->generation) + " R";
  1741 + result = getObjGenAsStr() + " R";
1740 1742 } else {
1741 1743 result = unparseResolved();
1742 1744 }
... ... @@ -1848,9 +1850,7 @@ QPDFObjectHandle::parse(
1848 1850 void
1849 1851 QPDFObjectHandle::pipePageContents(Pipeline* p)
1850 1852 {
1851   - std::string description = "page object " +
1852   - QUtil::int_to_string(this->objid) + " " +
1853   - QUtil::int_to_string(this->generation);
  1853 + std::string description = "page object " + getObjGenAsStr();
1854 1854 std::string all_description;
1855 1855 this->getKey("/Contents")
1856 1856 .pipeContentStreams(p, description, all_description);
... ... @@ -1869,15 +1869,12 @@ QPDFObjectHandle::pipeContentStreams(
1869 1869 buf.writeCStr("\n");
1870 1870 }
1871 1871 LastChar lc(&buf);
1872   - std::string og = QUtil::int_to_string(stream.getObjectID()) + " " +
1873   - QUtil::int_to_string(stream.getGeneration());
1874   - std::string w_description = "content stream object " + og;
1875 1872 if (!stream.pipeStreamData(&lc, 0, qpdf_dl_specialized)) {
1876 1873 QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent");
1877 1874 throw QPDFExc(
1878 1875 qpdf_e_damaged_pdf,
1879 1876 "content stream",
1880   - w_description,
  1877 + "content stream object " + stream.getObjGenAsStr(),
1881 1878 0,
1882 1879 "errors while decoding content stream");
1883 1880 }
... ... @@ -1893,9 +1890,7 @@ QPDFObjectHandle::pipeContentStreams(
1893 1890 void
1894 1891 QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
1895 1892 {
1896   - std::string description = "page object " +
1897   - QUtil::int_to_string(this->objid) + " " +
1898   - QUtil::int_to_string(this->generation);
  1893 + std::string description = "page object " + getObjGenAsStr();
1899 1894 this->getKey("/Contents")
1900 1895 .parseContentStream_internal(description, callbacks);
1901 1896 }
... ... @@ -1903,17 +1898,14 @@ QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
1903 1898 void
1904 1899 QPDFObjectHandle::parseAsContents(ParserCallbacks* callbacks)
1905 1900 {
1906   - std::string description = "object " + QUtil::int_to_string(this->objid) +
1907   - " " + QUtil::int_to_string(this->generation);
  1901 + std::string description = "object " + getObjGenAsStr();
1908 1902 this->parseContentStream_internal(description, callbacks);
1909 1903 }
1910 1904  
1911 1905 void
1912 1906 QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
1913 1907 {
1914   - std::string description = "token filter for page object " +
1915   - QUtil::int_to_string(this->objid) + " " +
1916   - QUtil::int_to_string(this->generation);
  1908 + auto description = "token filter for page object " + getObjGenAsStr();
1917 1909 Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
1918 1910 this->pipePageContents(&token_pipeline);
1919 1911 }
... ... @@ -1921,9 +1913,7 @@ QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
1921 1913 void
1922 1914 QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next)
1923 1915 {
1924   - std::string description = "token filter for object " +
1925   - QUtil::int_to_string(this->objid) + " " +
1926   - QUtil::int_to_string(this->generation);
  1916 + auto description = "token filter for object " + getObjGenAsStr();
1927 1917 Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
1928 1918 this->pipeStreamData(&token_pipeline, 0, qpdf_dl_specialized);
1929 1919 }
... ... @@ -2862,7 +2852,7 @@ QPDFObjectHandle::copyObject(
2862 2852 "attempt to make a stream into a direct object");
2863 2853 }
2864 2854  
2865   - QPDFObjGen cur_og(this->objid, this->generation);
  2855 + auto cur_og = getObjGen();
2866 2856 if (cur_og.getObj() != 0) {
2867 2857 if (visited.count(cur_og)) {
2868 2858 QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop");
... ... @@ -3204,14 +3194,13 @@ QPDFObjectHandle::dereference()
3204 3194 throw std::logic_error(
3205 3195 "attempted to dereference an uninitialized QPDFObjectHandle");
3206 3196 }
3207   - if (this->obj.get() && this->objid &&
3208   - QPDF::Resolver::objectChanged(
3209   - this->qpdf, QPDFObjGen(this->objid, this->generation), this->obj)) {
  3197 + if (this->obj.get() && getObjectID() &&
  3198 + QPDF::Resolver::objectChanged(this->qpdf, getObjGen(), this->obj)) {
3210 3199 this->obj = nullptr;
3211 3200 }
3212 3201 if (this->obj.get() == 0) {
3213 3202 std::shared_ptr<QPDFObject> obj =
3214   - QPDF::Resolver::resolve(this->qpdf, this->objid, this->generation);
  3203 + QPDF::Resolver::resolve(this->qpdf, getObjectID(), getGeneration());
3215 3204 if (obj.get() == 0) {
3216 3205 // QPDF::resolve never returns an uninitialized object, but
3217 3206 // check just in case.
... ...