Commit 68ac2179bd6fb6bda6e701ae676fc69cd85a4670

Authored by m-holger
1 parent c1377176

In ObjTable change maximum allowable object id to std::vector<T>::max_size()

Given that the PDF spec requires the xref table to contain entries for all
object ids <= the maximum id present in a PDF document, max_size is a
qpdf implementation limitation for legitimate object ids.
Showing 1 changed file with 7 additions and 4 deletions
libqpdf/qpdf/ObjTable.hh
@@ -113,6 +113,7 @@ class ObjTable: public std::vector&lt;T&gt; @@ -113,6 +113,7 @@ class ObjTable: public std::vector&lt;T&gt;
113 } 113 }
114 } 114 }
115 115
  116 +
116 inline void 117 inline void
117 forEach(std::function<void(int, const T&)> fn) 118 forEach(std::function<void(int, const T&)> fn)
118 { 119 {
@@ -131,24 +132,26 @@ class ObjTable: public std::vector&lt;T&gt; @@ -131,24 +132,26 @@ class ObjTable: public std::vector&lt;T&gt;
131 inline T& 132 inline T&
132 element(size_t idx) 133 element(size_t idx)
133 { 134 {
  135 + static const size_t max_size = std::vector<T>::max_size();
134 if (idx < std::vector<T>::size()) { 136 if (idx < std::vector<T>::size()) {
135 return std::vector<T>::operator[](idx); 137 return std::vector<T>::operator[](idx);
136 - } else if (idx < static_cast<size_t>(std::numeric_limits<int>::max())) { 138 + } else if (idx < max_size) {
137 return sparse_elements[idx]; 139 return sparse_elements[idx];
138 } 140 }
139 - throw std::runtime_error("Invalid object id accessing ObjTable."); 141 + throw std::runtime_error("Impossibly large object id encountered accessing ObjTable");
140 return element(0); // doesn't return 142 return element(0); // doesn't return
141 } 143 }
142 144
143 inline T const& 145 inline T const&
144 element(size_t idx) const 146 element(size_t idx) const
145 { 147 {
  148 + static const size_t max_size = std::vector<T>::max_size();
146 if (idx < std::vector<T>::size()) { 149 if (idx < std::vector<T>::size()) {
147 return std::vector<T>::operator[](idx); 150 return std::vector<T>::operator[](idx);
148 - } else if (idx < static_cast<size_t>(std::numeric_limits<int>::max())) { 151 + } else if (idx < max_size) {
149 return sparse_elements.at(idx); 152 return sparse_elements.at(idx);
150 } 153 }
151 - throw std::runtime_error("Invalid object id accessing ObjTable."); 154 + throw std::runtime_error("Impossibly large object id encountered accessing ObjTable");
152 return element(0); // doesn't return 155 return element(0); // doesn't return
153 } 156 }
154 }; 157 };