[gs-cvs] rev 8327 - trunk/gs/lib

alexcher at ghostscript.com alexcher at ghostscript.com
Sun Oct 28 07:19:46 PDT 2007


Author: alexcher
Date: 2007-10-28 07:19:46 -0700 (Sun, 28 Oct 2007)
New Revision: 8327

Modified:
   trunk/gs/lib/pdf_main.ps
   trunk/gs/lib/pdf_rbld.ps
Log:
Stop reading the xref+trailer at the closing ">>" because PDF 1.7 Reference
made "startxref" optional in some cases. Thanks to SaGS for thr patch.
Bug 688283.

DETAILS:
The PDF 1.7 Reference, section F.2.3 "First-Page Cross-Reference 
Table and Trailer (Part 3)", 2nd paragraph on page 1031 states:

   "The first-page trailer may optionally end with startxref, an 
    integer, and %%EOF, just as in an ordinary trailer. This 
    information is ignored."

(note the word "optionally"), so in such a case a PDF interpreter 
cannot rely on anything particular (like "startxref"/ "startref"/ 
"xref") to follow the trailer dictionary. Now consider a linearized 
PDF being incrementally updated, and you get that in the general 
case a "previous trailer" may lack the "startxref". Apparently, 
Acrobat does a similar thing when creating hybrid-ref PDFs.

DIFFERENCES:
None.


Modified: trunk/gs/lib/pdf_main.ps
===================================================================
--- trunk/gs/lib/pdf_main.ps	2007-10-27 19:55:00 UTC (rev 8326)
+++ trunk/gs/lib/pdf_main.ps	2007-10-28 14:19:46 UTC (rev 8327)
@@ -274,19 +274,19 @@
 % Read the cross-reference and trailer sections.
 
 /traileropdict mark
-  (<<) cvn { mark } bind
+  (<<) cvn { /dictlevelcount dictlevelcount 1 add store mark } bind
   (>>) cvn { { .dicttomark } stopped {
 	      (   **** File has unbalanced >> in trailer.\n) pdfformaterror
-             } if } bind
+             } if
+	     /dictlevelcount dictlevelcount 1 sub def
+             dictlevelcount 0 eq { exit } if
+           } bind
   ([) cvn { mark } bind		% ditto
   (]) cvn dup load
 %  /true true		% see .pdfexectoken in pdf_base.ps
 %  /false false		% ibid.
 %  /null null		% ibid.
   /R { /resolveR cvx 3 packedarray cvx } bind	% see Objects below
-  /startxref /exit load
-  /startref /exit load	% Some application (unknown) misspells startxref
-  /xref /exit load  % Adobe Acrobat 8.1 drops startxref in hybrid files.
 .dicttomark readonly def
 
 % Because of EOL conversion, lines with fixed contents might be followed
@@ -356,6 +356,7 @@
      (   **** Warning:  length of some xref entries is not equal to 20 bytes.\n)
      pdfformaterror
    } if
+   /dictlevelcount 0 def
    PDFfile traileropdict .pdfrun
  } bind def
 

Modified: trunk/gs/lib/pdf_rbld.ps
===================================================================
--- trunk/gs/lib/pdf_rbld.ps	2007-10-27 19:55:00 UTC (rev 8326)
+++ trunk/gs/lib/pdf_rbld.ps	2007-10-28 14:19:46 UTC (rev 8327)
@@ -209,6 +209,7 @@
   exch 2 div lt { search_start_trailer } { search_end_trailer } ifelse
   % get the trailer
   PDFfile exch setfileposition		% set to the specified trailer location
+  /dictlevelcount 0 def
   PDFfile traileropdict .pdfrun		% read trailer info
   /Trailer exch def
 } bind def



More information about the gs-cvs mailing list