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

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