diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index cd03ef1c..3fa0266c 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -2340,7 +2340,10 @@ QPDFObjectHandle::shallowCopy() if (isArray()) { QTC::TC("qpdf", "QPDFObjectHandle shallow copy array"); - new_obj = newArray(getArrayAsVector()); + // No newArray for shallow copying the sparse array + QPDF_Array* arr = dynamic_cast(m->obj.getPointer()); + new_obj = QPDFObjectHandle( + new QPDF_Array(arr->getElementsForShallowCopy())); } else if (isDictionary()) { diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 45635f8a..31cd2dbc 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -136,3 +136,9 @@ QPDF_Array::eraseItem(int at) { this->elements.erase(QIntC::to_size(at)); } + +SparseOHArray const& +QPDF_Array::getElementsForShallowCopy() const +{ + return this->elements; +} diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh index 08a5a608..eb0b594b 100644 --- a/libqpdf/qpdf/QPDF_Array.hh +++ b/libqpdf/qpdf/QPDF_Array.hh @@ -28,6 +28,8 @@ class QPDF_Array: public QPDFObject void appendItem(QPDFObjectHandle const& item); void eraseItem(int at); + SparseOHArray const& getElementsForShallowCopy() const; + protected: virtual void releaseResolved();