From 68ac2179bd6fb6bda6e701ae676fc69cd85a4670 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 31 Aug 2024 12:55:53 +0100 Subject: [PATCH] In ObjTable change maximum allowable object id to std::vector::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. --- libqpdf/qpdf/ObjTable.hh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libqpdf/qpdf/ObjTable.hh b/libqpdf/qpdf/ObjTable.hh index 84b51b78..9da96b30 100644 --- a/libqpdf/qpdf/ObjTable.hh +++ b/libqpdf/qpdf/ObjTable.hh @@ -113,6 +113,7 @@ class ObjTable: public std::vector } } + inline void forEach(std::function fn) { @@ -131,24 +132,26 @@ class ObjTable: public std::vector inline T& element(size_t idx) { + static const size_t max_size = std::vector::max_size(); if (idx < std::vector::size()) { return std::vector::operator[](idx); - } else if (idx < static_cast(std::numeric_limits::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::max_size(); if (idx < std::vector::size()) { return std::vector::operator[](idx); - } else if (idx < static_cast(std::numeric_limits::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 } };