From 62d1dd6d6e1b5d0f9b08795639ebb7c0f250398b Mon Sep 17 00:00:00 2001 From: m-holger Date: Mon, 18 Aug 2025 11:48:03 +0100 Subject: [PATCH] Redefine `Array::size()` to return 0 if the object is not an array --- libqpdf/QPDF_Array.cc | 6 ++++-- libqpdf/qpdf/QPDFObjectHandle_private.hh | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 4e2813f..ddbeba5 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -174,8 +174,10 @@ Array::null() const size_t Array::size() const { - auto a = array(); - return a->sp ? a->sp->size : a->elements.size(); + if (auto a = as()) { + return a->sp ? a->sp->size : a->elements.size(); + } + return 0; } std::pair diff --git a/libqpdf/qpdf/QPDFObjectHandle_private.hh b/libqpdf/qpdf/QPDFObjectHandle_private.hh index 74872b4..447754b 100644 --- a/libqpdf/qpdf/QPDFObjectHandle_private.hh +++ b/libqpdf/qpdf/QPDFObjectHandle_private.hh @@ -86,6 +86,7 @@ namespace qpdf const_reverse_iterator crend(); + // Return the number of elements in the array. Return 0 if the object is not an array. size_t size() const; std::pair at(int n) const; bool setAt(int at, QPDFObjectHandle const& oh); -- libgit2 0.21.4