From a3576a73593987b26cd3eff346f8f7c11f713cbd Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 14 Jun 2013 14:53:47 -0400 Subject: Bug fix: handle generation > 0 when generating object streams Rework QPDFWriter to always track old object IDs and QPDFObjGen instead of int, thus not discarding the generation number. Switch to QPDF::getCompressibleObjGen() to properly handle the case of an old object eligible for compression that has a generation of other than zero. --- include/qpdf/QPDF.hh | 13 ++++++++++++- include/qpdf/QPDFWriter.hh | 22 +++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index fd0c9b54..b90dea3b 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -434,8 +434,19 @@ class QPDF // Map object to object stream that contains it QPDF_DLL void getObjectStreamData(std::map&); + // Get a list of objects that would be permitted in an object - // stream + // stream. + QPDF_DLL + std::vector getCompressibleObjGens(); + + // Deprecated: get a list of objects that would be permitted in an + // object stream. This method is deprecated and will be removed. + // It's incorrect because it disregards the generations of the + // compressible objects, which can lead (and has lead) to bugs. + // This method will throw an exception if any of the objects + // returned have a generation of other than zero. Use + // getCompressibleObjGens() instead. QPDF_DLL std::vector getCompressibleObjects(); diff --git a/include/qpdf/QPDFWriter.hh b/include/qpdf/QPDFWriter.hh index e2f731d3..92104142 100644 --- a/include/qpdf/QPDFWriter.hh +++ b/include/qpdf/QPDFWriter.hh @@ -24,6 +24,7 @@ #include +#include #include #include @@ -289,7 +290,7 @@ class QPDFWriter void writeStringQDF(std::string const& str); void writeStringNoQDF(std::string const& str); void writePad(int nspaces); - void assignCompressedObjectNumbers(int objid); + void assignCompressedObjectNumbers(QPDFObjGen const& og); void enqueueObject(QPDFObjectHandle object); void writeObjectStreamOffsets( std::vector& offsets, int first_obj); @@ -380,6 +381,9 @@ class QPDFWriter void pushEncryptionFilter(); void pushDiscardFilter(); + void discardGeneration(std::map const& in, + std::map& out); + QPDF& pdf; char const* filename; FILE* file; @@ -419,7 +423,7 @@ class QPDFWriter std::list > to_delete; Pl_Count* pipeline; std::list object_queue; - std::map obj_renumber; + std::map obj_renumber; std::map xref; std::map lengths; int next_objid; @@ -427,12 +431,16 @@ class QPDFWriter size_t cur_stream_length; bool added_newline; int max_ostream_index; - std::set normalized_streams; - std::map page_object_to_seq; - std::map contents_to_page_seq; - std::map object_to_object_stream; - std::map > object_stream_to_objects; + std::set normalized_streams; + std::map page_object_to_seq; + std::map contents_to_page_seq; + std::map object_to_object_stream; + std::map > object_stream_to_objects; std::list pipeline_stack; + + // For linearization only + std::map obj_renumber_no_gen; + std::map object_to_object_stream_no_gen; }; #endif // __QPDFWRITER_HH__ -- cgit v1.2.3-54-g00ecf