Fix for 687946, /execstackoverflow in --forall--

Alex Cherepanov <[email protected]> Thu, 24 Mar 2005 15:30:28 -0500
Newsgroups gmane.comp.printing.ghostscript.patches
Organization Coscript Software
Message-ID <[email protected]>
Detect circular references in resource dictionaries by keeping
all visited resource dictionaries in a dictionary . Work around a bug in
PDF files produced by FyTek, Inc.
Bug 687946, customer 580.

_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review
pdf_main.ps.diff (text/plain, 1.4 KB)
--- S:\gs_cvs\gs\lib\pdf_main.ps	2005-03-18 16:56:54.000000000 -0500
+++ pdf_main.ps	2005-03-24 11:30:06.000000000 -0500
@@ -1190,15 +1190,22 @@
     pop false
   } {
     false exch {
-      dup resourceusestransparency { pop not exit } if
+      4 dict 1 index resourceusestransparency { pop not exit } if
       /Parent knownoget not { exit } if
     } loop
   } ifelse
 } bind def
-% Check the Resources of a page or Form.
-/resourceusestransparency {	% <dict> resourceusestransparency <bool>
+
+% Check the Resources of a page or Form. Check for loops in the resource chain.
+/resourceusestransparency {	% <dict> <dict> resourceusestransparency <bool>
   {	% Use loop to provide an exitable context.
     /Resources knownoget not { 0 dict } if
+    2 copy known {
+      (   **** File has circular references in resource dictionaries.\n)
+      pdfformaterror
+      pop false exit
+    } if
+    2 copy dup put
     dup /ExtGState knownoget {
       false exch {
 	exch pop oforce
@@ -1216,7 +1223,7 @@
 	exch pop oforce dup /Subtype get
 	dup /Image eq { 1 index /SMask known { pop pop not exit } if } if
 	/Form eq {
-	  resourceusestransparency { not exit } if
+	  3 index exch resourceusestransparency { not exit } if
 	} {
 	  pop
 	} ifelse
@@ -1224,6 +1231,7 @@
     } if
     pop false exit
   } loop
+  exch pop
 } bind def
 
 % ------ ColorSpace substitution support ------ %