diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 120f3593..57e30383 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -1196,6 +1196,7 @@ class QPDF Members(); Members(Members const&); + unsigned long long unique_id; QPDFTokenizer tokenizer; PointerHolder file; std::string last_object_description; @@ -1216,7 +1217,7 @@ class QPDF std::map pageobj_to_pages_pos; bool pushed_inherited_attributes_to_pages; std::vector warnings; - std::map object_copiers; + std::map object_copiers; PointerHolder copied_streams; // copied_stream_data_provider is owned by copied_streams CopiedStreamDataProvider* copied_stream_data_provider; diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 6d8f4fae..813775a2 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -89,6 +89,7 @@ QPDF::EncryptionParameters::EncryptionParameters() : } QPDF::Members::Members() : + unique_id(0), provided_password_is_hex_key(false), ignore_xref_streams(false), suppress_warnings(false), @@ -113,6 +114,12 @@ QPDF::QPDF() : m(new Members()) { m->tokenizer.allowEOF(); + // Generate a unique ID. It just has to be unique among all QPDF + // objects allocated throughout the lifetime of this running + // application. + m->unique_id = static_cast(QUtil::get_current_time()); + m->unique_id <<= 32; + m->unique_id |= static_cast(QUtil::random()); } QPDF::~QPDF() @@ -2103,7 +2110,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign, bool allow_page) "QPDF::copyForeign called with object from this QPDF"); } - ObjCopier& obj_copier = this->m->object_copiers[other]; + ObjCopier& obj_copier = this->m->object_copiers[other->m->unique_id]; if (! obj_copier.visiting.empty()) { throw std::logic_error("obj_copier.visiting is not empty"