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