Blame SOURCES/ghostscript-cve-2019-3835.patch

5e8686
From 779664d79f0dca77dbdd66b753679bfd12dcbbad Mon Sep 17 00:00:00 2001
5e8686
From: Chris Liddell <chris.liddell@artifex.com>
5e8686
Date: Mon, 26 Nov 2018 18:01:25 +0000
5e8686
Subject: [PATCH 1/4] Have gs_cet.ps run from gs_init.ps
5e8686
5e8686
Previously gs_cet.ps was run on the command line, to set up the interpreter
5e8686
state so our output more closely matches the example output for the QL CET
5e8686
tests.
5e8686
5e8686
Allow a -dCETMODE command line switch, which will cause gs_init.ps to run the
5e8686
file directly.
5e8686
5e8686
This works better for gpdl as it means the changes are made in the intial
5e8686
interpreter state, rather than after initialisation is complete.
5e8686
5e8686
This also means adding a definition of the default procedure for black
5e8686
generation and under color removal (rather it being defined in-line in
5e8686
.setdefaultbgucr
5e8686
5e8686
Also, add a check so gs_cet.ps only runs once - if we try to run it a second
5e8686
time, we'll just skip over the file, flushing through to the end.
5e8686
---
5e8686
 Resource/Init/gs_cet.ps  | 11 ++++++++++-
5e8686
 Resource/Init/gs_init.ps | 13 ++++++++++++-
5e8686
 2 files changed, 22 insertions(+), 2 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_cet.ps b/Resource/Init/gs_cet.ps
5e8686
index d3e1686..75534bb 100644
5e8686
--- a/Resource/Init/gs_cet.ps
5e8686
+++ b/Resource/Init/gs_cet.ps
5e8686
@@ -1,6 +1,11 @@
5e8686
 %!PS
5e8686
 % Set defaults for Ghostscript to match Adobe CPSI behaviour for CET
5e8686
 
5e8686
+systemdict /product get (PhotoPRINT SE 5.0v2) readonly eq
5e8686
+{
5e8686
+  (%END GS_CET) .skipeof
5e8686
+} if
5e8686
+
5e8686
 % do this in the server level so it is persistent across jobs
5e8686
 //true 0 startjob not {
5e8686
   (*** Warning: CET startup is not in server default) = flush
5e8686
@@ -25,7 +30,9 @@ currentglobal //true setglobal
5e8686
 
5e8686
 /UNROLLFORMS true def
5e8686
 
5e8686
-{ } bind dup
5e8686
+(%.defaultbgrucrproc) cvn { } bind def
5e8686
+
5e8686
+(%.defaultbgrucrproc) cvn load dup
5e8686
 setblackgeneration
5e8686
 setundercolorremoval
5e8686
 0 array cvx readonly dup dup dup setcolortransfer
5e8686
@@ -109,3 +116,5 @@ userdict /.smoothness currentsmoothness put
5e8686
 % end of slightly nasty hack to give consistent cluster results
5e8686
 
5e8686
 //false 0 startjob pop		% re-enter encapsulated mode
5e8686
+
5e8686
+%END GS_CET
5e8686
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
5e8686
index a2503f1..9a1f2b2 100644
5e8686
--- a/Resource/Init/gs_init.ps
5e8686
+++ b/Resource/Init/gs_init.ps
5e8686
@@ -1534,10 +1534,18 @@ setpacking
5e8686
   % any-part-of-pixel rule.
5e8686
   0.5 .setfilladjust
5e8686
 } bind def
5e8686
+
5e8686
 % Set the default screen and BG/UCR.
5e8686
+% We define the proc here, rather than inline in .setdefaultbgucr
5e8686
+% for the benefit of gs_cet.ps so jobs that do anything that causes
5e8686
+% .setdefaultbgucr to be called will still get the redefined proc
5e8686
+% in gs_cet.ps
5e8686
+(%.defaultbgrucrproc) cvn { pop 0 } def
5e8686
+
5e8686
 /.setdefaultbgucr {
5e8686
   systemdict /setblackgeneration known {
5e8686
-    { pop 0 } dup setblackgeneration setundercolorremoval
5e8686
+    (%.defaultbgrucrproc) cvn load dup
5e8686
+    setblackgeneration setundercolorremoval
5e8686
   } if
5e8686
 } bind def
5e8686
 /.useloresscreen {	% - .useloresscreen <bool>
5e8686
@@ -2506,4 +2514,7 @@ WRITESYSTEMDICT {
5e8686
 % be 'true' in some cases.
5e8686
 userdict /AGM_preserve_spots //false put
5e8686
 
5e8686
+systemdict /CETMODE .knownget
5e8686
+{ { (gs_cet.ps) runlibfile } if } if
5e8686
+
5e8686
 % The interpreter will run the initial procedure (start).
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From e8acf6d1aa1fc92f453175509bfdad6f2b12dc73 Mon Sep 17 00:00:00 2001
5e8686
From: Nancy Durgin <nancy.durgin@artifex.com>
5e8686
Date: Thu, 14 Feb 2019 10:09:00 -0800
5e8686
Subject: [PATCH 2/4] Undef /odef in gs_init.ps
5e8686
5e8686
Made a new temporary utility function in gs_cet.ps (.odef) to use instead
5e8686
of /odef.  This makes it fine to undef odef with all the other operators in
5e8686
gs_init.ps
5e8686
5e8686
This punts the bigger question of what to do with .makeoperator, but it
5e8686
doesn't make the situation any worse than it already was.
5e8686
---
5e8686
 Resource/Init/gs_cet.ps  | 10 ++++++++--
5e8686
 Resource/Init/gs_init.ps |  1 +
5e8686
 2 files changed, 9 insertions(+), 2 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_cet.ps b/Resource/Init/gs_cet.ps
5e8686
index 75534bb..dbc5c4e 100644
5e8686
--- a/Resource/Init/gs_cet.ps
5e8686
+++ b/Resource/Init/gs_cet.ps
5e8686
@@ -1,6 +1,10 @@
5e8686
 %!PS
5e8686
 % Set defaults for Ghostscript to match Adobe CPSI behaviour for CET
5e8686
 
5e8686
+/.odef {		% <name> <proc> odef -
5e8686
+  1 index exch .makeoperator def
5e8686
+} bind def
5e8686
+
5e8686
 systemdict /product get (PhotoPRINT SE 5.0v2) readonly eq
5e8686
 {
5e8686
   (%END GS_CET) .skipeof
5e8686
@@ -93,8 +97,8 @@ userdict /.smoothness currentsmoothness put
5e8686
    } {
5e8686
      /setsmoothness .systemvar /typecheck signalerror
5e8686
    } ifelse
5e8686
-} bind odef
5e8686
-/currentsmoothness { userdict /.smoothness get } bind odef % for 09-55.PS, 09-57.PS .
5e8686
+} bind //.odef exec
5e8686
+/currentsmoothness { userdict /.smoothness get } bind //.odef exec % for 09-55.PS, 09-57.PS .
5e8686
 
5e8686
 % slightly nasty hack to give consistent cluster results
5e8686
 /ofnfa systemdict /filenameforall get def
5e8686
@@ -113,6 +117,8 @@ userdict /.smoothness currentsmoothness put
5e8686
   } ifelse
5e8686
   ofnfa
5e8686
 } bind def
5e8686
+
5e8686
+currentdict /.odef undef
5e8686
 % end of slightly nasty hack to give consistent cluster results
5e8686
 
5e8686
 //false 0 startjob pop		% re-enter encapsulated mode
5e8686
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
5e8686
index 9a1f2b2..e5678b9 100644
5e8686
--- a/Resource/Init/gs_init.ps
5e8686
+++ b/Resource/Init/gs_init.ps
5e8686
@@ -2253,6 +2253,7 @@ SAFER { .setsafeglobal } if
5e8686
   /.systemvmSFD /.settrapparams /.currentsystemparams /.currentuserparams /.getsystemparam /.getuserparam /.setsystemparams /.setuserparams
5e8686
   /.checkpassword /.locale_to_utf8 /.currentglobal /.gcheck /.imagepath /.currentoutputdevice
5e8686
   /.type /.writecvs /.setSMask /.currentSMask /.needinput /.countexecstack /.execstack /.applypolicies
5e8686
+  /odef
5e8686
 
5e8686
   % Used by a free user in the Library of Congress. Apparently this is used to
5e8686
   % draw a partial page, which is then filled in by the results of a barcode
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From 205591753126802da850ada6511a0ff8411aa287 Mon Sep 17 00:00:00 2001
5e8686
From: Ray Johnston <ray.johnston@artifex.com>
5e8686
Date: Thu, 14 Feb 2019 10:20:03 -0800
5e8686
Subject: [PATCH 3/4] Fix bug 700585: Restrict superexec and remove it from
5e8686
 internals and gs_cet.ps
5e8686
5e8686
Also while changing things, restructure the CETMODE so that it will
5e8686
work with -dSAFER. The gs_cet.ps is now run when we are still at save
5e8686
level 0 with systemdict writeable. Allows us to undefine .makeoperator
5e8686
and .setCPSImode internal operators after CETMODE is handled.
5e8686
5e8686
Change previous uses of superexec to using .forceput (with the usual
5e8686
.bind executeonly to hide it).
5e8686
---
5e8686
 Resource/Init/gs_cet.ps   | 39 ++++++++++++++-------------------------
5e8686
 Resource/Init/gs_dps1.ps  |  2 +-
5e8686
 Resource/Init/gs_fonts.ps |  8 ++++----
5e8686
 Resource/Init/gs_init.ps  | 38 +++++++++++++++++++++++++++-----------
5e8686
 Resource/Init/gs_ttf.ps   |  6 +++---
5e8686
 Resource/Init/gs_type1.ps |  6 +++---
5e8686
 6 files changed, 52 insertions(+), 47 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_cet.ps b/Resource/Init/gs_cet.ps
5e8686
index dbc5c4e..58da404 100644
5e8686
--- a/Resource/Init/gs_cet.ps
5e8686
+++ b/Resource/Init/gs_cet.ps
5e8686
@@ -1,37 +1,28 @@
5e8686
-%!PS
5e8686
 % Set defaults for Ghostscript to match Adobe CPSI behaviour for CET
5e8686
 
5e8686
-/.odef {		% <name> <proc> odef -
5e8686
-  1 index exch .makeoperator def
5e8686
-} bind def
5e8686
-
5e8686
+% skip if we've already run this -- based on fake "product"
5e8686
 systemdict /product get (PhotoPRINT SE 5.0v2) readonly eq
5e8686
 {
5e8686
   (%END GS_CET) .skipeof
5e8686
 } if
5e8686
 
5e8686
-% do this in the server level so it is persistent across jobs
5e8686
-//true 0 startjob not {
5e8686
-  (*** Warning: CET startup is not in server default) = flush
5e8686
-} if
5e8686
+% Note: this must be run at save level 0 and when systemdict is writeable
5e8686
+currentglobal //true setglobal
5e8686
+systemdict dup dup dup
5e8686
+/version (3017.102) readonly .forceput         % match CPSI 3017.102
5e8686
+/product (PhotoPRINT SE 5.0v2) readonly .forceput      % match CPSI 3017.102
5e8686
+/revision 0 put                        % match CPSI 3017.103 Tek shows revision 5
5e8686
+/serialnumber dup {233640} readonly .makeoperator .forceput % match CPSI 3017.102 Tek shows serialnumber 1401788461
5e8686
+
5e8686
+systemdict /.odef {           % <name> <proc> odef -
5e8686
+  1 index exch //.makeoperator def
5e8686
+} .bind .forceput          % this will be undefined at the end
5e8686
 
5e8686
 300 .sethiresscreen	% needed for language switch build since it
5e8686
                         % processes gs_init.ps BEFORE setting the resolution
5e8686
 
5e8686
 0 array 0 setdash % CET 09-08 wants local setdash
5e8686
 
5e8686
-currentglobal //true setglobal
5e8686
-
5e8686
-{
5e8686
-  systemdict dup dup dup
5e8686
-  /version (3017.102) readonly put		% match CPSI 3017.102
5e8686
-  /product (PhotoPRINT SE 5.0v2) readonly put	% match CPSI 3017.102
5e8686
-  /revision 0 put			% match CPSI 3017.103 Tek shows revision 5
5e8686
-  /serialnumber dup {233640} readonly .makeoperator put % match CPSI 3017.102 Tek shows serialnumber 1401788461
5e8686
-  systemdict /deviceinfo undef                  % for CET 20-23-1
5e8686
-%  /UNROLLFORMS true put                 % CET files do unreasonable things inside forms
5e8686
-} 1183615869 internaldict /superexec get exec
5e8686
-
5e8686
 /UNROLLFORMS true def
5e8686
 
5e8686
 (%.defaultbgrucrproc) cvn { } bind def
5e8686
@@ -118,9 +109,7 @@ userdict /.smoothness currentsmoothness put
5e8686
   ofnfa
5e8686
 } bind def
5e8686
 
5e8686
-currentdict /.odef undef
5e8686
-% end of slightly nasty hack to give consistent cluster results
5e8686
-
5e8686
-//false 0 startjob pop		% re-enter encapsulated mode
5e8686
+systemdict /.odef .undef
5e8686
 
5e8686
+% end of slightly nasty hack to give consistent cluster results
5e8686
 %END GS_CET
5e8686
diff --git a/Resource/Init/gs_dps1.ps b/Resource/Init/gs_dps1.ps
5e8686
index b75ea14..01475ac 100644
5e8686
--- a/Resource/Init/gs_dps1.ps
5e8686
+++ b/Resource/Init/gs_dps1.ps
5e8686
@@ -85,7 +85,7 @@ level2dict begin
5e8686
                 % definition, copy it into the local directory.
5e8686
       //systemdict /SharedFontDirectory .knownget
5e8686
        { 1 index .knownget
5e8686
-          { //.FontDirectory 2 index 3 -1 roll { put } systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse } % readonly
5e8686
+          { //.FontDirectory 2 index 3 -1 roll .forceput } % readonly
5e8686
          if
5e8686
        }
5e8686
       if
5e8686
diff --git a/Resource/Init/gs_fonts.ps b/Resource/Init/gs_fonts.ps
5e8686
index 01eca35..ab062e1 100644
5e8686
--- a/Resource/Init/gs_fonts.ps
5e8686
+++ b/Resource/Init/gs_fonts.ps
5e8686
@@ -512,11 +512,11 @@ buildfontdict 3 /.buildfont3 cvx put
5e8686
                 % the font in LocalFontDirectory.
5e8686
    .currentglobal
5e8686
     { //systemdict /LocalFontDirectory .knownget
5e8686
-       { 2 index 2 index { .growput } systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse }	% readonly
5e8686
+       { 2 index 2 index .forceput }	% readonly
5e8686
       if
5e8686
     }
5e8686
    if
5e8686
-   dup //.FontDirectory 4 -2 roll { .growput } systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse	% readonly
5e8686
+   dup //.FontDirectory 4 -2 roll .forceput % readonly
5e8686
                 % If the font originated as a resource, register it.
5e8686
    currentfile .currentresourcefile eq { dup .registerfont } if
5e8686
    readonly
5e8686
@@ -1178,13 +1178,13 @@ currentdict /.putgstringcopy .forceundef
5e8686
           //.FontDirectory 1 index known not {
5e8686
             2 dict dup /FontName 3 index put
5e8686
             dup /FontType 1 put
5e8686
-            //.FontDirectory 3 1 roll { put } systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse   % readonly
5e8686
+            //.FontDirectory 3 1 roll //.forceput exec % readonly
5e8686
           } {
5e8686
             pop
5e8686
           } ifelse
5e8686
         } forall
5e8686
       } forall
5e8686
-    }
5e8686
+    } executeonly	% hide .forceput
5e8686
 FAKEFONTS { exch } if pop def   % don't bind, .current/setglobal get redefined
5e8686
 
5e8686
 % Install initial fonts from Fontmap.
5e8686
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
5e8686
index e5678b9..a054222 100644
5e8686
--- a/Resource/Init/gs_init.ps
5e8686
+++ b/Resource/Init/gs_init.ps
5e8686
@@ -2184,9 +2184,6 @@ SAFER { .setsafeglobal } if
5e8686
   /.endtransparencygroup     % transparency-example.ps
5e8686
   /.setdotlength             % Bug687720.ps
5e8686
   /.sort /.setdebug /.mementolistnewblocks /getenv
5e8686
-
5e8686
-  /.makeoperator /.setCPSImode              % gs_cet.ps, this won't work on cluster with -dSAFER
5e8686
-
5e8686
   /unread
5e8686
   ]
5e8686
   {systemdict exch .forceundef} forall
5e8686
@@ -2266,7 +2263,6 @@ SAFER { .setsafeglobal } if
5e8686
 
5e8686
   % Used by our own test suite files
5e8686
   %/.fileposition %image-qa.ps
5e8686
-  %/.makeoperator /.setCPSImode % gs_cet.ps
5e8686
 
5e8686
   % Either our code uses these in ways which mean they can't be undefined, or they are used directly by
5e8686
   % test files/utilities, or engineers expressed a desire to keep them visible.
5e8686
@@ -2471,6 +2467,16 @@ end
5e8686
 /vmreclaim where
5e8686
  { pop NOGC not { 2 .vmreclaim 0 vmreclaim } if
5e8686
  } if
5e8686
+
5e8686
+% Do this before systemdict is locked (see below for additional CETMODE setup using gs_cet.ps)
5e8686
+systemdict /CETMODE .knownget {
5e8686
+  {
5e8686
+    (gs_cet.ps) runlibfile
5e8686
+  } if
5e8686
+} if
5e8686
+systemdict /.makeoperator .undef	% must be after gs_cet.ps
5e8686
+systemdict /.setCPSImode .undef		% must be after gs_cet.ps
5e8686
+
5e8686
 DELAYBIND not {
5e8686
   systemdict /.bindnow .undef       % We only need this for DELAYBIND
5e8686
   systemdict /.forcecopynew .undef	% remove temptation
5e8686
@@ -2479,16 +2485,29 @@ DELAYBIND not {
5e8686
   systemdict /.forceundef .undef	% ditto
5e8686
 } if
5e8686
 
5e8686
-% Move superexec to internaldict if superexec is defined.
5e8686
-systemdict /superexec .knownget {
5e8686
-  1183615869 internaldict /superexec 3 -1 roll put
5e8686
-  systemdict /superexec .undef
5e8686
+% Move superexec to internaldict if superexec is defined. (Level 2 or later)
5e8686
+systemdict /superexec known {
5e8686
+  % restrict superexec to single known use by PScript5.dll
5e8686
+  % We could do this only for SAFER mode, but internaldict and superexec are
5e8686
+  % not very well documented, and we don't want them to be used.
5e8686
+  1183615869 internaldict /superexec {
5e8686
+    2 index /Private eq                % first check for typical use in PScript5.dll
5e8686
+    1 index length 1 eq and    % expected usage is: dict /Private <value> {put} superexec
5e8686
+    1 index 0 get systemdict /put get eq and
5e8686
+    {
5e8686
+      //superexec exec         % the only usage we allow
5e8686
+    } {
5e8686
+      /superexec load /invalidaccess signalerror
5e8686
+    } ifelse
5e8686
+  } bind cvx executeonly put
5e8686
+  systemdict /superexec .undef % get rid of the dangerous (unrestricted) operator
5e8686
 } if
5e8686
 
5e8686
 %% Can't remove this one until the last minute :-)
5e8686
 DELAYBIND not {
5e8686
 systemdict /.undef .undef
5e8686
 } if
5e8686
+
5e8686
 WRITESYSTEMDICT {
5e8686
    SAFER {
5e8686
        (\n *** WARNING - you have selected SAFER, indicating you want Ghostscript\n) print
5e8686
@@ -2515,7 +2534,4 @@ WRITESYSTEMDICT {
5e8686
 % be 'true' in some cases.
5e8686
 userdict /AGM_preserve_spots //false put
5e8686
 
5e8686
-systemdict /CETMODE .knownget
5e8686
-{ { (gs_cet.ps) runlibfile } if } if
5e8686
-
5e8686
 % The interpreter will run the initial procedure (start).
5e8686
diff --git a/Resource/Init/gs_ttf.ps b/Resource/Init/gs_ttf.ps
5e8686
index 05943c5..996d1e2 100644
5e8686
--- a/Resource/Init/gs_ttf.ps
5e8686
+++ b/Resource/Init/gs_ttf.ps
5e8686
@@ -1421,7 +1421,7 @@ mark
5e8686
           TTFDEBUG { (\n1 setting alias: ) print dup ==only
5e8686
                 ( to be the same as  ) print 2 index //== exec } if
5e8686
 
5e8686
-          7 index 2 index 3 -1 roll exch //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse
5e8686
+          7 index 2 index 3 -1 roll exch .forceput
5e8686
         } forall
5e8686
         pop pop pop
5e8686
       }
5e8686
@@ -1439,7 +1439,7 @@ mark
5e8686
           exch pop
5e8686
           TTFDEBUG { (\n2 setting alias: ) print 1 index ==only
5e8686
                      ( to use glyph index: ) print dup //== exec } if
5e8686
-          5 index 3 1 roll //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse
5e8686
+          5 index 3 1 roll .forceput
5e8686
           //false
5e8686
         }
5e8686
         {
5e8686
@@ -1456,7 +1456,7 @@ mark
5e8686
         {                            %  CharStrings(dict) isunicode(boolean) cmap(dict) RAGL(dict) gname(name) codep(integer) gindex(integer)
5e8686
           TTFDEBUG { (\3 nsetting alias: ) print 1 index ==only
5e8686
                 ( to be index: ) print dup //== exec } if
5e8686
-          exch pop 5 index 3 1 roll //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse
5e8686
+          exch pop 5 index 3 1 roll .forceput
5e8686
         }
5e8686
         {
5e8686
           pop pop
5e8686
@@ -1486,7 +1486,7 @@ mark
5e8686
       } ifelse
5e8686
     ]
5e8686
   TTFDEBUG { (Encoding: ) print dup === flush } if
5e8686
-} bind def
5e8686
+} .bind executeonly odef               % hides .forceput
5e8686
5e8686
 % to be removed 9.09......
5e8686
 currentdict /postalias undef
5e8686
diff --git a/Resource/Init/gs_type1.ps b/Resource/Init/gs_type1.ps
5e8686
index 2935d9c..1f38dd7 100644
5e8686
--- a/Resource/Init/gs_type1.ps
5e8686
+++ b/Resource/Init/gs_type1.ps
5e8686
@@ -116,7 +116,7 @@
5e8686
                  {                                               % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname aglname
5e8686
                    CFFDEBUG { (\nsetting alias: ) print dup ==only
5e8686
                          ( to be the same as glyph: ) print 1 index //== exec } if
5e8686
-                   3 index exch 3 index //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse
5e8686
+                   3 index exch 3 index .forceput
5e8686
                                                                  % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname
5e8686
                  }
5e8686
                  {pop} ifelse
5e8686
@@ -135,7 +135,7 @@
5e8686
          3 1 roll pop pop
5e8686
      } if
5e8686
      pop
5e8686
-     dup /.AGLprocessed~GS //true //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse
5e8686
+     dup /.AGLprocessed~GS //true .forceput
5e8686
    } if
5e8686
 
5e8686
    %% We need to excute the C .buildfont1 in a stopped context so that, if there
5e8686
@@ -148,7 +148,7 @@
5e8686
    {//.buildfont1} stopped
5e8686
    4 3 roll .setglobal
5e8686
    {//.buildfont1 $error /errorname get signalerror} if
5e8686
- } bind def
5e8686
+ } .bind executeonly def	% hide .forceput
5e8686
 
5e8686
 % If the diskfont feature isn't included, define a dummy .loadfontdict.
5e8686
 /.loadfontdict where
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From d683d1e6450d74619e6277efeebfc222d9a5cb91 Mon Sep 17 00:00:00 2001
5e8686
From: Ray Johnston <ray.johnston@artifex.com>
5e8686
Date: Sun, 24 Feb 2019 22:01:04 -0800
5e8686
Subject: [PATCH 4/4] Bug 700585: Obliterate "superexec". We don't need it, nor
5e8686
 do any known apps.
5e8686
5e8686
We were under the impression that the Windows driver 'PScript5.dll' used
5e8686
superexec, but after testing with our extensive suite of PostScript file,
5e8686
and analysis of the PScript5 "Adobe CoolType ProcSet, it does not appear
5e8686
that this operator is needed anymore. Get rid of superexec and all of the
5e8686
references to it, since it is a potential security hole.
5e8686
---
5e8686
 Resource/Init/gs_init.ps | 18 ------------------
5e8686
 psi/icontext.c           |  1 -
5e8686
 psi/icstate.h            |  1 -
5e8686
 psi/zcontrol.c           | 30 ------------------------------
5e8686
 psi/zdict.c              |  6 ++----
5e8686
 psi/zgeneric.c           |  3 +--
5e8686
 6 files changed, 3 insertions(+), 56 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
5e8686
index a054222..ca20f12 100644
5e8686
--- a/Resource/Init/gs_init.ps
5e8686
+++ b/Resource/Init/gs_init.ps
5e8686
@@ -2485,24 +2485,6 @@ DELAYBIND not {
5e8686
   systemdict /.forceundef .undef	% ditto
5e8686
 } if
5e8686
 
5e8686
-% Move superexec to internaldict if superexec is defined. (Level 2 or later)
5e8686
-systemdict /superexec known {
5e8686
-  % restrict superexec to single known use by PScript5.dll
5e8686
-  % We could do this only for SAFER mode, but internaldict and superexec are
5e8686
-  % not very well documented, and we don't want them to be used.
5e8686
-  1183615869 internaldict /superexec {
5e8686
-    2 index /Private eq                % first check for typical use in PScript5.dll
5e8686
-    1 index length 1 eq and    % expected usage is: dict /Private <value> {put} superexec
5e8686
-    1 index 0 get systemdict /put get eq and
5e8686
-    {
5e8686
-      //superexec exec         % the only usage we allow
5e8686
-    } {
5e8686
-      /superexec load /invalidaccess signalerror
5e8686
-    } ifelse
5e8686
-  } bind cvx executeonly put
5e8686
-  systemdict /superexec .undef % get rid of the dangerous (unrestricted) operator
5e8686
-} if
5e8686
-
5e8686
 %% Can't remove this one until the last minute :-)
5e8686
 DELAYBIND not {
5e8686
 systemdict /.undef .undef
5e8686
diff --git a/psi/icontext.c b/psi/icontext.c
5e8686
index 1fbe486..7462ea3 100644
5e8686
--- a/psi/icontext.c
5e8686
+++ b/psi/icontext.c
5e8686
@@ -151,7 +151,6 @@ context_state_alloc(gs_context_state_t ** ppcst,
5e8686
     pcst->rand_state = rand_state_initial;
5e8686
     pcst->usertime_total = 0;
5e8686
     pcst->keep_usertime = false;
5e8686
-    pcst->in_superexec = 0;
5e8686
     pcst->plugin_list = 0;
5e8686
     make_t(&pcst->error_object, t__invalid);
5e8686
     {	/*
5e8686
diff --git a/psi/icstate.h b/psi/icstate.h
5e8686
index 4c6a14d..1009d85 100644
5e8686
--- a/psi/icstate.h
5e8686
+++ b/psi/icstate.h
5e8686
@@ -54,7 +54,6 @@ struct gs_context_state_s {
5e8686
     long usertime_total;	/* total accumulated usertime, */
5e8686
                                 /* not counting current time if running */
5e8686
     bool keep_usertime;		/* true if context ever executed usertime */
5e8686
-    int in_superexec;		/* # of levels of superexec */
5e8686
     /* View clipping is handled in the graphics state. */
5e8686
     ref error_object;		/* t__invalid or error object from operator */
5e8686
     ref userparams;		/* t_dictionary */
5e8686
diff --git a/psi/zcontrol.c b/psi/zcontrol.c
5e8686
index 0362cf4..dc813e8 100644
5e8686
--- a/psi/zcontrol.c
5e8686
+++ b/psi/zcontrol.c
5e8686
@@ -158,34 +158,6 @@ zexecn(i_ctx_t *i_ctx_p)
5e8686
     return o_push_estack;
5e8686
 }
5e8686
 
5e8686
-/* <obj> superexec - */
5e8686
-static int end_superexec(i_ctx_t *);
5e8686
-static int
5e8686
-zsuperexec(i_ctx_t *i_ctx_p)
5e8686
-{
5e8686
-    os_ptr op = osp;
5e8686
-    es_ptr ep;
5e8686
-
5e8686
-    check_op(1);
5e8686
-    if (!r_has_attr(op, a_executable))
5e8686
-        return 0;		/* literal object just gets pushed back */
5e8686
-    check_estack(2);
5e8686
-    ep = esp += 3;
5e8686
-    make_mark_estack(ep - 2, es_other, end_superexec); /* error case */
5e8686
-    make_op_estack(ep - 1,  end_superexec); /* normal case */
5e8686
-    ref_assign(ep, op);
5e8686
-    esfile_check_cache();
5e8686
-    pop(1);
5e8686
-    i_ctx_p->in_superexec++;
5e8686
-    return o_push_estack;
5e8686
-}
5e8686
-static int
5e8686
-end_superexec(i_ctx_t *i_ctx_p)
5e8686
-{
5e8686
-    i_ctx_p->in_superexec--;
5e8686
-    return 0;
5e8686
-}
5e8686
-
5e8686
 /* <array> <executable> .runandhide <obj>				*/
5e8686
 /* 	before executing  <executable>, <array> is been removed from	*/
5e8686
 /*	the operand stack and placed on the execstack with attributes	*/
5e8686
@@ -971,8 +943,6 @@ const op_def zcontrol3_op_defs[] = {
5e8686
     {"0%loop_continue", loop_continue},
5e8686
     {"0%repeat_continue", repeat_continue},
5e8686
     {"0%stopped_push", stopped_push},
5e8686
-    {"1superexec", zsuperexec},
5e8686
-    {"0%end_superexec", end_superexec},
5e8686
     {"2.runandhide", zrunandhide},
5e8686
     {"0%end_runandhide", end_runandhide},
5e8686
     op_def_end(0)
5e8686
diff --git a/psi/zdict.c b/psi/zdict.c
5e8686
index b0deaaa..e2e525d 100644
5e8686
--- a/psi/zdict.c
5e8686
+++ b/psi/zdict.c
5e8686
@@ -212,8 +212,7 @@ zundef(i_ctx_t *i_ctx_p)
5e8686
     int code;
5e8686
 
5e8686
     check_type(*op1, t_dictionary);
5e8686
-    if (i_ctx_p->in_superexec == 0)
5e8686
-        check_dict_write(*op1);
5e8686
+    check_dict_write(*op1);
5e8686
     code = idict_undef(op1, op);
5e8686
     if (code < 0 && code != gs_error_undefined) /* ignore undefined error */
5e8686
         return code;
5e8686
@@ -504,8 +503,7 @@ zsetmaxlength(i_ctx_t *i_ctx_p)
5e8686
     int code;
5e8686
 
5e8686
     check_type(*op1, t_dictionary);
5e8686
-    if (i_ctx_p->in_superexec == 0)
5e8686
-        check_dict_write(*op1);
5e8686
+    check_dict_write(*op1);
5e8686
     check_type(*op, t_integer);
5e8686
     if (op->value.intval < 0)
5e8686
         return_error(gs_error_rangecheck);
5e8686
diff --git a/psi/zgeneric.c b/psi/zgeneric.c
5e8686
index 8048e28..d4edddb 100644
5e8686
--- a/psi/zgeneric.c
5e8686
+++ b/psi/zgeneric.c
5e8686
@@ -204,8 +204,7 @@ zput(i_ctx_t *i_ctx_p)
5e8686
 
5e8686
     switch (r_type(op2)) {
5e8686
         case t_dictionary:
5e8686
-            if (i_ctx_p->in_superexec == 0)
5e8686
-                check_dict_write(*op2);
5e8686
+            check_dict_write(*op2);
5e8686
             {
5e8686
                 int code = idict_put(op2, op1, op);
5e8686
 
5e8686
-- 
5e8686
2.20.1
5e8686