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

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