summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2014-01-10 17:54:19 +0000
committerRobin Watts <robin.watts@artifex.com>2014-01-13 15:44:38 +0000
commit00f3869f8eecc202fe5f736825de5a5ee8ca4b3a (patch)
treeb61a84c637f338211d1e1873bbd7d9f80ddc1400
parentc2980368cc3b03b755629c506720121ddd60e406 (diff)
downloadmupdf-00f3869f8eecc202fe5f736825de5a5ee8ca4b3a.tar.xz
More fixes for PDF clean.
Avoid negative indirections. Don't make indirections to objects that aren't going to be used. Also improve pdf-write.c so that it doesn't call renumberobj on objs that are going to be dropped.
-rw-r--r--source/pdf/pdf-object.c4
-rw-r--r--source/pdf/pdf-write.c15
2 files changed, 15 insertions, 4 deletions
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c
index eff0128b..0ee399c5 100644
--- a/source/pdf/pdf-object.c
+++ b/source/pdf/pdf-object.c
@@ -158,6 +158,10 @@ pdf_new_indirect(pdf_document *doc, int num, int gen)
{
pdf_obj *obj;
fz_context *ctx = doc->ctx;
+
+ if (num <= 0 || gen < 0)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Invalid num (%d) or gen (%d) for indirection", num, gen);
+
obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(indirect)");
obj->doc = doc;
obj->refs = 1;
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 36fda444..b5894421 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -723,7 +723,7 @@ static void renumberobj(pdf_document *doc, pdf_write_options *opts, pdf_obj *obj
if (pdf_is_indirect(val))
{
int o = pdf_to_num(val);
- if (o >= xref_len)
+ if (o >= xref_len || o <= 0 || opts->renumber_map[o] == 0)
val = pdf_new_null(doc);
else
val = pdf_new_indirect(doc, opts->renumber_map[o], 0);
@@ -746,7 +746,7 @@ static void renumberobj(pdf_document *doc, pdf_write_options *opts, pdf_obj *obj
if (pdf_is_indirect(val))
{
int o = pdf_to_num(val);
- if (o >= xref_len)
+ if (o >= xref_len || o <= 0 || opts->renumber_map[o] == 0)
val = pdf_new_null(doc);
else
val = pdf_new_indirect(doc, opts->renumber_map[o], 0);
@@ -779,11 +779,18 @@ static void renumberobjs(pdf_document *doc, pdf_write_options *opts)
renumberobj(doc, opts, pdf_trailer(doc));
for (num = 0; num < xref_len; num++)
{
- pdf_obj *obj = pdf_get_xref_entry(doc, num)->obj;
+ pdf_obj *obj;
+ int to = opts->renumber_map[num];
+
+ /* If object is going to be dropped, don't bother renumbering */
+ if (to == 0)
+ continue;
+
+ obj = pdf_get_xref_entry(doc, num)->obj;
if (pdf_is_indirect(obj))
{
- obj = pdf_new_indirect(doc, opts->renumber_map[pdf_to_num(obj)], 0);
+ obj = pdf_new_indirect(doc, to, 0);
pdf_update_object(doc, num, obj);
pdf_drop_obj(obj);
}