diff options
author | Jay Berkenbilt <ejb@ql.org> | 2013-06-14 20:53:47 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2013-06-14 20:58:09 +0200 |
commit | a3576a73593987b26cd3eff346f8f7c11f713cbd (patch) | |
tree | 3db5b39d339cddacf2fc1b13ecf4c028bc0589b5 /include | |
parent | 96eb96511557469d50bbd55d211ced16acc31e13 (diff) | |
download | qpdf-a3576a73593987b26cd3eff346f8f7c11f713cbd.tar.zst |
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.
Diffstat (limited to 'include')
-rw-r--r-- | include/qpdf/QPDF.hh | 13 | ||||
-rw-r--r-- | include/qpdf/QPDFWriter.hh | 22 |
2 files changed, 27 insertions, 8 deletions
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<int, int>&); + // Get a list of objects that would be permitted in an object - // stream + // stream. + QPDF_DLL + std::vector<QPDFObjGen> 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<int> 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 <qpdf/Constants.h> +#include <qpdf/QPDFObjGen.hh> #include <qpdf/QPDFXRefEntry.hh> #include <qpdf/Pl_Buffer.hh> @@ -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<qpdf_offset_t>& offsets, int first_obj); @@ -380,6 +381,9 @@ class QPDFWriter void pushEncryptionFilter(); void pushDiscardFilter(); + void discardGeneration(std::map<QPDFObjGen, int> const& in, + std::map<int, int>& out); + QPDF& pdf; char const* filename; FILE* file; @@ -419,7 +423,7 @@ class QPDFWriter std::list<PointerHolder<Pipeline> > to_delete; Pl_Count* pipeline; std::list<QPDFObjectHandle> object_queue; - std::map<int, int> obj_renumber; + std::map<QPDFObjGen, int> obj_renumber; std::map<int, QPDFXRefEntry> xref; std::map<int, qpdf_offset_t> lengths; int next_objid; @@ -427,12 +431,16 @@ class QPDFWriter size_t cur_stream_length; bool added_newline; int max_ostream_index; - std::set<int> normalized_streams; - std::map<int, int> page_object_to_seq; - std::map<int, int> contents_to_page_seq; - std::map<int, int> object_to_object_stream; - std::map<int, std::set<int> > object_stream_to_objects; + std::set<QPDFObjGen> normalized_streams; + std::map<QPDFObjGen, int> page_object_to_seq; + std::map<QPDFObjGen, int> contents_to_page_seq; + std::map<QPDFObjGen, int> object_to_object_stream; + std::map<int, std::set<QPDFObjGen> > object_stream_to_objects; std::list<Pipeline*> pipeline_stack; + + // For linearization only + std::map<int, int> obj_renumber_no_gen; + std::map<int, int> object_to_object_stream_no_gen; }; #endif // __QPDFWRITER_HH__ |