summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-repair.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2014-11-25 19:57:29 +0000
committerRobin Watts <robin.watts@artifex.com>2014-11-26 11:24:30 +0000
commite767bd783d91ae88cd79da19e79afb2c36bcf32a (patch)
treeae0544ae1641fdd9efdbd608ad0bf0b8618669ec /source/pdf/pdf-repair.c
parent37779f92eda4a7adf4b0f0212f89680beca77c5c (diff)
downloadmupdf-e767bd783d91ae88cd79da19e79afb2c36bcf32a.tar.xz
Change xref representation to cope better with sparse xrefs.
Currently each xref in the file results in an array from 0 to num_objects. If we have a file that has been updated many times this causes a huge waste of memory. Instead we now hold each xref as a list of non-overlapping subsections (exactly as the file holds them). Lookup is therefore potentially slower, but only on files where the xrefs are highly fragmented (i.e. where we would be saving in memory terms). Some parts of our code (notably the file writing code that does garbage collection etc) assumes that lookups of object entry pointers will not change previous object entry pointers that have been looked up. To cope with this, and to cope with the case where we are updating/creating new objects, we introduce the idea of a 'solid' xref. A solid xref is one where it has a single subsection record that spans the entire range of valid object numbers for a file. Once we have ensured that an xref is 'solid', we can safely work on the pointers within it without fear of them moving. We ensure that any 'incremental' xref is solid. We also ensure that any non-incremental write makes the xref solid.
Diffstat (limited to 'source/pdf/pdf-repair.c')
-rw-r--r--source/pdf/pdf-repair.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index 1193a45c..7e35c5fb 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -204,7 +204,7 @@ pdf_repair_obj_stm(pdf_document *doc, int num, int gen)
fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i);
continue;
}
- else if (n > MAX_OBJECT_NUMBER)
+ else if (n >= pdf_xref_len(doc))
{
fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i);
continue;
@@ -455,7 +455,9 @@ pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf)
Dummy access to entry to assure sufficient space in the xref table
and avoid repeated reallocs in the loop
*/
- (void)pdf_get_populating_xref_entry(doc, maxnum);
+ /* Ensure that the first xref table is a 'solid' one from
+ * 0 to maxnum. */
+ pdf_ensure_solid_xref(doc, maxnum);
for (i = 0; i < listlen; i++)
{