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