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

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