[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-2051-g147591b

[email protected] (Ken Sharp) Mon, 6 Jan 2020 16:30:22 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  147591b7a8390d0e98418851b60ac67e659cf2f1 (commit)
      from  9a2414c7f88ef07cb9297bdeb3236cdba44c25ad (commit)

----------------------------------------------------------------------
commit 147591b7a8390d0e98418851b60ac67e659cf2f1
Author: Ken Sharp <[email protected]>
Date:   Mon Jan 6 16:30:17 2020 +0000

    PDF interpreter - don't abort on errors in JBIG2 globals
    
    This was due to Julian's work on comparing jbig2dec with Luratech.
    
    The test file 'normal_716.pdf' and the cluster test file
    jbig2_null_segments_and_glyphs.pdf throw errors when trying to read
    the JBIG2 globals dictionary. Luratech doesn't cache the globals, while
    jbig2dec does, and the problem was that jbig2dec was returning an error
    at a point where the PDF interpreter wasn't able to ignore it, while
    Luratech deferred the error to a later point, at a time when the
    interpreter could, and did, ignore it.
    
    This meant that Luratech continued to render any further content on the
    page while jbig2dec did not, resulting in diffs.
    
    This commit simply runs the global context extraction in a stopped
    context. If it fails we clean up the stack and exit, which (effectively)
    defers the error to the same point as the Luratech decoder.

diff --git a/Resource/Init/pdf_base.ps b/Resource/Init/pdf_base.ps
index fd1636d..618e5e5 100644
--- a/Resource/Init/pdf_base.ps
+++ b/Resource/Init/pdf_base.ps
@@ -1251,16 +1251,26 @@ currentdict /pdf_rules_dict undef
   dup /JBIG2Globals knownoget {
     % make global ctx
     PDFfile fileposition exch % resolvestream is not reentrant
+    mark exch
     //true resolvestream 		% stack after: PDFfileposition -file-
     % Read the data in a loop until EOF to so we can move the strings into a bytestring
     [ { counttomark 1 add index 60000 string readstring not { exit } if } loop ]
     exch pop 0 1 index { length add } forall	% compute the total length
     % now copy the data from the array of strings into a bytestring
     .bytestring exch 0 exch { 3 copy putinterval length add } forall pop
-    .jbig2makeglobalctx
-    PDFfile 3 -1 roll setfileposition
-    1 index exch
-    /.jbig2globalctx exch put
+    % If this fails we don't want to abort totally, there may be more content
+    % in the PDF file that we can render. So just run in a stopped context.
+    {.jbig2makeglobalctx} stopped
+    {
+      cleartomark
+      PDFfile exch setfileposition
+    }
+    {
+      exch pop
+      PDFfile 3 -1 roll setfileposition
+      1 index exch
+      /.jbig2globalctx exch put
+    } ifelse
   } if
 } bind executeonly def
 


Summary of changes:
 Resource/Init/pdf_base.ps | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)