Commit 7588cac2957f66c6f0e3f5fb5b691ecbb8f3e0b2

Authored by Jay Berkenbilt
1 parent e27ac682

Create an application-scope unique ID for each QPDF object

Use this instead of QPDF* as a map key for object_copiers.
include/qpdf/QPDF.hh
... ... @@ -1196,6 +1196,7 @@ class QPDF
1196 1196 Members();
1197 1197 Members(Members const&);
1198 1198  
  1199 + unsigned long long unique_id;
1199 1200 QPDFTokenizer tokenizer;
1200 1201 PointerHolder<InputSource> file;
1201 1202 std::string last_object_description;
... ... @@ -1216,7 +1217,7 @@ class QPDF
1216 1217 std::map<QPDFObjGen, int> pageobj_to_pages_pos;
1217 1218 bool pushed_inherited_attributes_to_pages;
1218 1219 std::vector<QPDFExc> warnings;
1219   - std::map<QPDF*, ObjCopier> object_copiers;
  1220 + std::map<unsigned long long, ObjCopier> object_copiers;
1220 1221 PointerHolder<QPDFObjectHandle::StreamDataProvider> copied_streams;
1221 1222 // copied_stream_data_provider is owned by copied_streams
1222 1223 CopiedStreamDataProvider* copied_stream_data_provider;
... ...
libqpdf/QPDF.cc
... ... @@ -89,6 +89,7 @@ QPDF::EncryptionParameters::EncryptionParameters() :
89 89 }
90 90  
91 91 QPDF::Members::Members() :
  92 + unique_id(0),
92 93 provided_password_is_hex_key(false),
93 94 ignore_xref_streams(false),
94 95 suppress_warnings(false),
... ... @@ -113,6 +114,12 @@ QPDF::QPDF() :
113 114 m(new Members())
114 115 {
115 116 m->tokenizer.allowEOF();
  117 + // Generate a unique ID. It just has to be unique among all QPDF
  118 + // objects allocated throughout the lifetime of this running
  119 + // application.
  120 + m->unique_id = static_cast<unsigned long>(QUtil::get_current_time());
  121 + m->unique_id <<= 32;
  122 + m->unique_id |= static_cast<unsigned long>(QUtil::random());
116 123 }
117 124  
118 125 QPDF::~QPDF()
... ... @@ -2103,7 +2110,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign, bool allow_page)
2103 2110 "QPDF::copyForeign called with object from this QPDF");
2104 2111 }
2105 2112  
2106   - ObjCopier& obj_copier = this->m->object_copiers[other];
  2113 + ObjCopier& obj_copier = this->m->object_copiers[other->m->unique_id];
2107 2114 if (! obj_copier.visiting.empty())
2108 2115 {
2109 2116 throw std::logic_error("obj_copier.visiting is not empty"
... ...