2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-23 03:18:59 +00:00

Create an application-scope unique ID for each QPDF object

Use this instead of QPDF* as a map key for object_copiers.
This commit is contained in:
Jay Berkenbilt 2019-01-06 10:07:23 -05:00
parent e27ac682e0
commit 7588cac295
2 changed files with 10 additions and 2 deletions

View File

@ -1196,6 +1196,7 @@ class QPDF
Members(); Members();
Members(Members const&); Members(Members const&);
unsigned long long unique_id;
QPDFTokenizer tokenizer; QPDFTokenizer tokenizer;
PointerHolder<InputSource> file; PointerHolder<InputSource> file;
std::string last_object_description; std::string last_object_description;
@ -1216,7 +1217,7 @@ class QPDF
std::map<QPDFObjGen, int> pageobj_to_pages_pos; std::map<QPDFObjGen, int> pageobj_to_pages_pos;
bool pushed_inherited_attributes_to_pages; bool pushed_inherited_attributes_to_pages;
std::vector<QPDFExc> warnings; std::vector<QPDFExc> warnings;
std::map<QPDF*, ObjCopier> object_copiers; std::map<unsigned long long, ObjCopier> object_copiers;
PointerHolder<QPDFObjectHandle::StreamDataProvider> copied_streams; PointerHolder<QPDFObjectHandle::StreamDataProvider> copied_streams;
// copied_stream_data_provider is owned by copied_streams // copied_stream_data_provider is owned by copied_streams
CopiedStreamDataProvider* copied_stream_data_provider; CopiedStreamDataProvider* copied_stream_data_provider;

View File

@ -89,6 +89,7 @@ QPDF::EncryptionParameters::EncryptionParameters() :
} }
QPDF::Members::Members() : QPDF::Members::Members() :
unique_id(0),
provided_password_is_hex_key(false), provided_password_is_hex_key(false),
ignore_xref_streams(false), ignore_xref_streams(false),
suppress_warnings(false), suppress_warnings(false),
@ -113,6 +114,12 @@ QPDF::QPDF() :
m(new Members()) m(new Members())
{ {
m->tokenizer.allowEOF(); 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<unsigned long>(QUtil::get_current_time());
m->unique_id <<= 32;
m->unique_id |= static_cast<unsigned long>(QUtil::random());
} }
QPDF::~QPDF() QPDF::~QPDF()
@ -2103,7 +2110,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign, bool allow_page)
"QPDF::copyForeign called with object from this QPDF"); "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()) if (! obj_copier.visiting.empty())
{ {
throw std::logic_error("obj_copier.visiting is not empty" throw std::logic_error("obj_copier.visiting is not empty"