Bug 708176: Cope with "undersized" cross-reference streams.
authorRobin Watts <[email protected]>
Wed, 5 Feb 2025 19:42:07 +0000 (19:42 +0000)
committerSebastian Rasmussen <[email protected]>
Fri, 7 Mar 2025 13:17:33 +0000 (14:17 +0100)
Cross reference streams contain a 'Size' entry. This is supposed
to be 1 larger than the largest object 'used' in the file.

The example given is not counting the cross reference stream
itself when calculating this value.

Fix our code to tolerate this.

source/pdf/pdf-xref.c

index ce861fa6beb45daed8e9caafce3ccba484c6bbdd..7c5fad6c3ac909bcd1614ae36a018dca9c8359eb 100644 (file)
@@ -1420,6 +1420,11 @@ pdf_read_new_xref(fz_context *ctx, pdf_document *doc)
 
                size = pdf_to_int(ctx, obj);
 
+               /* Bug708176: If the PDF file producer has declared Size without
+                * including this object, then increment it. */
+               if (size == num)
+                       pdf_dict_put_int(ctx, trailer, PDF_NAME(Size), size+1);
+
                obj = pdf_dict_get(ctx, trailer, PDF_NAME(W));
                if (!obj)
                        fz_throw(ctx, FZ_ERROR_FORMAT, "xref stream missing W entry (%d  R)", num);