Fix for 686998 syntax error in findxref

"Dan Coby" <[email protected]>
Newsgroups gmane.comp.printing.ghostscript.patches
Message-ID <[email protected]>
Fix for 686998 syntax error in findxref for customer 580.  The given
test file does not have 'startxref' on its own line.  This is a
violation of the PDF spec.  However Adobe Acrobat accepts the file.
This fix adds a check for this case and prints a warning message.
File processing then continues.

DETAILS:

This fix also includes moving the findxref inside of a stopped context
check in case any other problems are encountered while searching for
the xref table.  If a problem is now found during findxref, the xref
rebuild logic will be called.


Dan


Index: lib/pdf_main.ps
===================================================================
RCS file: /cvs/ghostscript/gs/lib/pdf_main.ps,v
retrieving revision 1.76
diff -c -5 -r1.76 pdf_main.ps
*** lib/pdf_main.ps	8 Aug 2003 18:45:05 -0000	1.76
--- lib/pdf_main.ps	15 Aug 2003 00:08:55 -0000
***************
*** 340,369 ****
     /Repaired false def
     PDFfile dup 0 setfileposition pdfstring readstring
     not {/pdfopen cvx /syntaxerror signalerror} if
     (%PDF-) search not {/pdfopen cvx /syntaxerror signalerror} if
     length /PDFoffset exch def pop cvr /PDFversion exch def
-    findxref
-    initPDFobjects
- 	% we currently have one object on stack.
- 	% we doo not include it in pdfemptycount
-    count 1 sub /pdfemptycount exch def
  	% Read the last cross-reference table.
!    { readxref } .internalstopped {
       print_xref_warning
       count pdfemptycount sub { pop } repeat % remove anything left by
readxref
       search_objects
-      count /pdfemptycount exch def
       search_trailer
     } { /Trailer exch def
  	% Read any previous cross-reference tables.
       Trailer
       { /Prev knownoget not { exit } if
         { readxref } .internalstopped {
           print_xref_warning
           count pdfemptycount sub { pop } repeat	% remove anything left by
readxref
  	 search_objects
  	 exit
         } if
       } loop
     } ifelse
     Trailer /Encrypt known {
--- 340,367 ----
     /Repaired false def
     PDFfile dup 0 setfileposition pdfstring readstring
     not {/pdfopen cvx /syntaxerror signalerror} if
     (%PDF-) search not {/pdfopen cvx /syntaxerror signalerror} if
     length /PDFoffset exch def pop cvr /PDFversion exch def
  	% Read the last cross-reference table.
!    /pdfemptycount count def
!    { initPDFobjects findxref readxref } .internalstopped {
!         % Read failed.  Attempt to recover xref data.
       print_xref_warning
       count pdfemptycount sub { pop } repeat % remove anything left by
readxref
       search_objects
       search_trailer
     } { /Trailer exch def
  	% Read any previous cross-reference tables.
       Trailer
       { /Prev knownoget not { exit } if
         { readxref } .internalstopped {
+          % Read failed.  Attempt to recover xref data.
           print_xref_warning
           count pdfemptycount sub { pop } repeat	% remove anything left by
readxref
           search_objects
+          search_trailer
           exit
         } if
       } loop
     } ifelse
     Trailer /Encrypt known {
***************
*** 413,424 ****
    PDFfile exch setfileposition
  	% Now read the startxref and xref start position.
    prevline token not { null } if dup type /integertype eq {
      exch pop cvi		% xref start position
      exch PDFfile exch setfileposition
!     prevline (startxref) linene { /findxref cvx /syntaxerror signalerror }
if
!     pop
    } {	% else, this file has 'startxref #####' format
      (startxref) ne { /findxref cvx /syntaxerror signalerror } if
      cvi		% xref start position
      (   **** Warning: format of the startxref line in this file is
invalid.\n)
      pdfformaterror
--- 411,435 ----
    PDFfile exch setfileposition
  	% Now read the startxref and xref start position.
    prevline token not { null } if dup type /integertype eq {
      exch pop cvi		% xref start position
      exch PDFfile exch setfileposition
!     prevline dup (startxref) linene {
!       % startxref not on a line by itself.  We have found PDF from
!       % www.verypdf.com in which the startxref was on the same line as
!       % the end of trailer dictionary.  Check for this.  Note:  This
!       % violates the spec.
!       dup (startxref) search {
! 	% found startxref - print warning
! 	pop pop pop 			% clear strings from search
!         (   **** Warning: format of the startxref line in this file is
invalid.\n)
!         pdfformaterror
!       } {				% no startxref - we have a problem.
!         /findxref cvx /syntaxerror signalerror
!       } ifelse
!     } if
!     pop pop
    } {	% else, this file has 'startxref #####' format
      (startxref) ne { /findxref cvx /syntaxerror signalerror } if
      cvi		% xref start position
      (   **** Warning: format of the startxref line in this file is
invalid.\n)
      pdfformaterror
Index: lib/pdf_rbld.ps
===================================================================
RCS file: /cvs/ghostscript/gs/lib/pdf_rbld.ps,v
retrieving revision 1.3
diff -c -5 -r1.3 pdf_rbld.ps
*** lib/pdf_rbld.ps	19 May 2003 06:18:11 -0000	1.3
--- lib/pdf_rbld.ps	15 Aug 2003 00:08:55 -0000
***************
*** 222,234 ****

  % This routine will scan a file searaching for object locations to build
  % an alternate version of the data in the xref tables.
  % Its purpose is to provide a basis for an xref fixing facility.
  /search_objects				% - search_objects -
! { % Reset the Objects and Generations larrays
!   /Objects larray def
!   /Generations lstring def
    % reset duplicate object and generation numbers error flag
    /dup_obj_gen_num false def
    % Determine how many bytes are in the file after the final %%EOF
    /post_eof_count determine_post_eof_count def
    % Start at the beginning of the file
--- 222,233 ----

  % This routine will scan a file searaching for object locations to build
  % an alternate version of the data in the xref tables.
  % Its purpose is to provide a basis for an xref fixing facility.
  /search_objects				% - search_objects -
! { % Initialize the Objects, Generations, etc. larrays
!   initPDFobjects
    % reset duplicate object and generation numbers error flag
    /dup_obj_gen_num false def
    % Determine how many bytes are in the file after the final %%EOF
    /post_eof_count determine_post_eof_count def
    % Start at the beginning of the file
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.