From a01359189b32c60c2d55b039f7aefd6c3ce0ebde Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 4 Jan 2019 10:17:33 -0500 Subject: Fix dangling references (fixes #240) On certain operations, such as iterating through all objects and adding new indirect objects, walk through the entire object structure and explicitly resolve any indirect references to non-existent objects. That prevents new objects from springing into existence and causing the previously dangling references to point to them. --- include/qpdf/QPDF.hh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 2e27d831..34e0ad31 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -431,9 +431,21 @@ class QPDF QPDF_DLL void showXRefTable(); + // Detect all indirect references to objects that don't exist and + // resolve them by replacing them with null, which is how the PDF + // spec says to interpret such dangling references. This method is + // called automatically if you try to add any new objects, if you + // call getAllObjects, and before a file is written. The qpdf + // object caches whether it has run this to avoid running it + // multiple times. You can pass true to force it to run again if + // you have explicitly added new objects that may have additional + // dangling references. + QPDF_DLL + void fixDanglingReferences(bool force = false); + // Return the approximate number of indirect objects. It is // approximate because not all objects in the file are preserved - // in all cases. + // in all cases, and gaps in object numbering are not preserved. QPDF_DLL size_t getObjectCount(); @@ -1199,6 +1211,7 @@ class QPDF CopiedStreamDataProvider* copied_stream_data_provider; std::set attachment_streams; bool reconstructed_xref; + bool fixed_dangling_refs; // Linearization data qpdf_offset_t first_xref_item_offset; // actual value from file -- cgit v1.2.3-70-g09d2