2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-09-22 10:09:06 +00:00

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.
This commit is contained in:
m-holger 2024-08-31 12:55:53 +01:00
parent c1377176f8
commit 68ac2179bd

View File

@ -113,6 +113,7 @@ class ObjTable: public std::vector<T>
}
}
inline void
forEach(std::function<void(int, const T&)> fn)
{
@ -131,24 +132,26 @@ class ObjTable: public std::vector<T>
inline T&
element(size_t idx)
{
static const size_t max_size = std::vector<T>::max_size();
if (idx < std::vector<T>::size()) {
return std::vector<T>::operator[](idx);
} else if (idx < static_cast<size_t>(std::numeric_limits<int>::max())) {
} else if (idx < max_size) {
return sparse_elements[idx];
}
throw std::runtime_error("Invalid object id accessing ObjTable.");
throw std::runtime_error("Impossibly large object id encountered accessing ObjTable");
return element(0); // doesn't return
}
inline T const&
element(size_t idx) const
{
static const size_t max_size = std::vector<T>::max_size();
if (idx < std::vector<T>::size()) {
return std::vector<T>::operator[](idx);
} else if (idx < static_cast<size_t>(std::numeric_limits<int>::max())) {
} else if (idx < max_size) {
return sparse_elements.at(idx);
}
throw std::runtime_error("Invalid object id accessing ObjTable.");
throw std::runtime_error("Impossibly large object id encountered accessing ObjTable");
return element(0); // doesn't return
}
};