From 148e6b9dae3900f1acd053df10bc41f06be5c507 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 25 Jun 2013 15:32:02 +0100 Subject: Ensure that xref_sections always grow over time. Never allow a new xref_section to be smaller than a previous one, as this makes pdf_xref_len(xref) get unexpectedly smaller. --- source/pdf/pdf-xref.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source/pdf') diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index 9aa1eab6..001fa62d 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -67,6 +67,11 @@ static void pdf_populate_next_xref_level(pdf_document *doc) xref->len = 0; xref->table = NULL; xref->trailer = NULL; + /* All new levels must be at least as big as the level before */ + if (doc->num_xref_sections > 1) + { + pdf_resize_xref(doc->ctx, xref, doc->xref_sections[doc->num_xref_sections - 2].len); + } } pdf_obj *pdf_trailer(pdf_document *doc) @@ -159,6 +164,9 @@ static pdf_xref_entry *pdf_get_new_xref_entry(pdf_document *doc, int i) } xref = &doc->xref_sections[0]; + /* All new levels must be at least as big as the level before */ + if (doc->xref_sections[1].len > i) + i = doc->xref_sections[1].len-1; if (i >= xref->len) pdf_resize_xref(ctx, xref, i + 1); -- cgit v1.2.3