diff options
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 27740f09..af862bd4 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -864,6 +864,7 @@ QPDFObjectHandle::setArrayItem(int n, QPDFObjectHandle const& item) { if (isArray()) { + checkOwnership(item); dynamic_cast<QPDF_Array*>(obj.getPointer())->setItem(n, item); } else @@ -878,6 +879,10 @@ QPDFObjectHandle::setArrayFromVector(std::vector<QPDFObjectHandle> const& items) { if (isArray()) { + for (auto const& item: items) + { + checkOwnership(item); + } dynamic_cast<QPDF_Array*>(obj.getPointer())->setFromVector(items); } else @@ -906,6 +911,7 @@ QPDFObjectHandle::appendItem(QPDFObjectHandle const& item) { if (isArray()) { + checkOwnership(item); dynamic_cast<QPDF_Array*>(obj.getPointer())->appendItem(item); } else @@ -1283,6 +1289,7 @@ QPDFObjectHandle::replaceKey(std::string const& key, { if (isDictionary()) { + checkOwnership(value); dynamic_cast<QPDF_Dictionary*>( obj.getPointer())->replaceKey(key, value); } @@ -1313,6 +1320,7 @@ QPDFObjectHandle::replaceOrRemoveKey(std::string const& key, { if (isDictionary()) { + checkOwnership(value); dynamic_cast<QPDF_Dictionary*>( obj.getPointer())->replaceOrRemoveKey(key, value); } @@ -3270,6 +3278,20 @@ QPDFObjectHandle::isImage(bool exclude_imagemask) } void +QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const +{ + if ((this->qpdf != nullptr) && + (item.qpdf != nullptr) && + (this->qpdf != item.qpdf)) + { + QTC::TC("qpdf", "QPDFObjectHandle check ownership"); + throw std::logic_error( + "Attempting to add an object from a different QPDF." + " Use QPDF::copyForeignObject to add objects from another file."); + } +} + +void QPDFObjectHandle::assertPageObject() { if (! isPageObject()) |