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

5e8686
From 95aa78beae9489d5c9f898fe2032aa23f860867d Mon Sep 17 00:00:00 2001
5e8686
From: Ray Johnston <ray.johnston@artifex.com>
5e8686
Date: Fri, 21 Sep 2018 11:16:18 -0700
5e8686
Subject: [PATCH 1/6] Catch errors in setpagesize, .setpagesize and
5e8686
 setpagedevice and cleanup
5e8686
5e8686
Bug 699794 showed that attempt to change page size in SAFER mode when the
5e8686
nulldevice was the currentdevice would leave 'false' on the stack. Run
5e8686
.setdevice in stopped and clean up, and also clean up .setpagesize
5e8686
---
5e8686
 Resource/Init/gs_lev2.ps  |  9 ++++++++-
5e8686
 Resource/Init/gs_setpd.ps |  9 +++++++--
5e8686
 Resource/Init/gs_statd.ps | 22 ++++++++++++++++++----
5e8686
 3 files changed, 33 insertions(+), 7 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_lev2.ps b/Resource/Init/gs_lev2.ps
5e8686
index b69303d..ab0c32e 100644
5e8686
--- a/Resource/Init/gs_lev2.ps
5e8686
+++ b/Resource/Init/gs_lev2.ps
5e8686
@@ -616,7 +616,14 @@ currentuserparams /WaitTimeout known
5e8686
    .dicttomark setpagedevice
5e8686
    /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
5e8686
  } bind def
5e8686
-/.setpagesize { 2 array astore /PageSize .dict1 setpagedevice } bind def
5e8686
+/.setpagesize
5e8686
+ { 2 copy 2 array astore /PageSize .dict1 { setpagedevice } stopped {
5e8686
+     pop	% the setpagedevice dict
5e8686
+     /setpagesize $error /errorname get signalerror
5e8686
+   } {
5e8686
+     pop pop	% success -- pop the arguments
5e8686
+   } ifelse
5e8686
+ } bind def
5e8686
 /setduplexmode { /Duplex .dict1 setpagedevice } bind def
5e8686
 /setmargins
5e8686
  { exch 2 array astore /Margins .dict1 setpagedevice
5e8686
diff --git a/Resource/Init/gs_setpd.ps b/Resource/Init/gs_setpd.ps
5e8686
index 46e5810..7875d1f 100644
5e8686
--- a/Resource/Init/gs_setpd.ps
5e8686
+++ b/Resource/Init/gs_setpd.ps
5e8686
@@ -932,10 +932,15 @@ SETPDDEBUG { (Recovering.) = pstack flush } if
5e8686
                 % Stack: mark ... <merged> <failed> <device> <eraseflag>
5e8686
 SETPDDEBUG { (Installing.) = pstack flush } if
5e8686
 
5e8686
-    pop
5e8686
+   pop
5e8686
                 % .setdevice clears the current page device!
5e8686
    .currentpagedevice pop exch
5e8686
-   .setdevice pop
5e8686
+   { .setdevice } stopped {
5e8686
+     cleartomark exch pop
5e8686
+     /setpagedevice $error /errorname get
5e8686
+     signalerror
5e8686
+   } if
5e8686
+   pop
5e8686
    .setpagedevice
5e8686
 
5e8686
                 % Implement UseCIEColor directly if this is a LL3 system.
5e8686
diff --git a/Resource/Init/gs_statd.ps b/Resource/Init/gs_statd.ps
5e8686
index 64c6463..34b759c 100644
5e8686
--- a/Resource/Init/gs_statd.ps
5e8686
+++ b/Resource/Init/gs_statd.ps
5e8686
@@ -39,7 +39,13 @@ statusdict begin
5e8686
 % These procedures are also accessed as data structures during initialization,
5e8686
 % so the page dimensions must be the first two elements of the procedure.
5e8686
 
5e8686
-/.setpagesize { /statusdict .systemvar begin .setpagesize end } bind def
5e8686
+/.setpagesize {
5e8686
+   /statusdict .systemvar begin
5e8686
+   { .setpagesize } stopped {
5e8686
+     /setpagesize $error /errorname get signalerror
5e8686
+   } if
5e8686
+   end
5e8686
+} bind def
5e8686
 
5e8686
                 % Page sizes defined by Adobe documentation
5e8686
                 % Note: these executable arrays should all begin with two
5e8686
@@ -261,9 +267,17 @@ readonly def
5e8686
                 % The Adobe documentation only defines setpagetype
5e8686
                 % (a Level 1 operator) as accepting the values 0 and 1,
5e8686
                 % so we do too.
5e8686
-      {/letter /note} 1 index get
5e8686
-      //systemdict /userdict get exch get cvx exec
5e8686
-      /pagetype exch def
5e8686
+      dup type /integertype ne {
5e8686
+        /setpage /typecheck signalerror
5e8686
+      } {
5e8686
+        dup 0 ne 1 index 1 ne or {
5e8686
+          /setpage /rangecheck signalerror
5e8686
+        } {
5e8686
+          {/letter /note} 1 index get
5e8686
+          //systemdict /userdict get exch get cvx exec
5e8686
+        } ifelse
5e8686
+        /pagetype exch def
5e8686
+    } ifelse
5e8686
     end
5e8686
   } bind def
5e8686
 
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From c29ec2fff76e45bbf9cd767ff541556c5d064be4 Mon Sep 17 00:00:00 2001
5e8686
From: Ray Johnston <ray.johnston@artifex.com>
5e8686
Date: Fri, 21 Sep 2018 12:00:50 -0700
5e8686
Subject: [PATCH 2/6] Add parameter checking in setresolution
5e8686
5e8686
Found in sequence for bug 699794
5e8686
---
5e8686
 Resource/Init/gs_lev2.ps | 9 ++++++++-
5e8686
 1 file changed, 8 insertions(+), 1 deletion(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_lev2.ps b/Resource/Init/gs_lev2.ps
5e8686
index ab0c32e..0f0d573 100644
5e8686
--- a/Resource/Init/gs_lev2.ps
5e8686
+++ b/Resource/Init/gs_lev2.ps
5e8686
@@ -637,7 +637,14 @@ currentuserparams /WaitTimeout known
5e8686
    .dicttomark setpagedevice
5e8686
  } bind def
5e8686
 /setresolution
5e8686
- { dup 2 array astore /HWResolution .dict1 setpagedevice
5e8686
+ { count 1 lt { /setresolution /stackunderflow signalerror } if
5e8686
+   dup type dup /integertype eq exch /realtype eq or not
5e8686
+   {
5e8686
+      /setresolution /typecheck signalerror
5e8686
+   } if
5e8686
+   dup 2 array astore /HWResolution .dict1 { setpagedevice } stopped {
5e8686
+     pop /setresolution $error /errorname get signalerror
5e8686
+   } if
5e8686
  } bind def
5e8686
 %END PAGEDEVICE
5e8686
 
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From fe4c47d8e25d6366ecbb5ff487348148b908a89e Mon Sep 17 00:00:00 2001
5e8686
From: Nancy Durgin <nancy.durgin@artifex.com>
5e8686
Date: Tue, 13 Nov 2018 14:23:41 -0800
5e8686
Subject: [PATCH 3/6] Undefine some level2-related operators
5e8686
5e8686
These are only a partial set.  Undefine them in both the level2dict and
5e8686
systemdict.  They are undef'd in gs_init.ps because they are used outside
5e8686
the scope of just gs_lev2.ps
5e8686
5e8686
      /.execform1
5e8686
      /.getdevparams
5e8686
      /.setuserparams2
5e8686
      /.startjob
5e8686
      /.checkFilePermitparams
5e8686
      /.checksetparams
5e8686
      /.copyparam
5e8686
      /.setpagesize
5e8686
5e8686
Rename .dict1 to .pair2dict and use immediate reference.
5e8686
5e8686
Undef these at end of gs_lev2.ps (should never make it into systemdict):
5e8686
      /.pair2dict
5e8686
      /.checkprocesscomment
5e8686
---
5e8686
 Resource/Init/gs_init.ps | 18 ++++++++++++++++++
5e8686
 Resource/Init/gs_lev2.ps | 34 +++++++++++++++++++++-------------
5e8686
 2 files changed, 39 insertions(+), 13 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
5e8686
index 48bb96d..e915f11 100644
5e8686
--- a/Resource/Init/gs_init.ps
5e8686
+++ b/Resource/Init/gs_init.ps
5e8686
@@ -2271,6 +2271,24 @@ SAFER { .setsafeglobal } if
5e8686
   ]
5e8686
   {systemdict exch .forceundef} forall
5e8686
 
5e8686
+  % level 2 operators, undefine from both systemdict and level2dict
5e8686
+  [
5e8686
+      /.execform1
5e8686
+      /.getdevparams
5e8686
+      /.setuserparams2
5e8686
+      /.startjob
5e8686
+      /.checkFilePermitparams
5e8686
+      /.checksetparams
5e8686
+      /.copyparam
5e8686
+      /.setpagesize
5e8686
+
5e8686
+% Couldn't figure out how to do these yet
5e8686
+%      /.checkparamtype
5e8686
+%      /.startnewjob
5e8686
+  ]
5e8686
+  dup {level2dict exch .forceundef} forall
5e8686
+  {systemdict exch .forceundef} forall
5e8686
+
5e8686
   //systemdict /UndefinePostScriptOperators .forceundef
5e8686
 } .bind executeonly def % must be bound and hidden for .forceundef
5e8686
 
5e8686
diff --git a/Resource/Init/gs_lev2.ps b/Resource/Init/gs_lev2.ps
5e8686
index 0f0d573..e6f0645 100644
5e8686
--- a/Resource/Init/gs_lev2.ps
5e8686
+++ b/Resource/Init/gs_lev2.ps
5e8686
@@ -64,7 +64,7 @@ level2dict begin
5e8686
       pop
5e8686
     } ifelse pop pop
5e8686
   } forall pop pop
5e8686
-} .bind def	% not odef, shouldn't reset stacks
5e8686
+} .bind odef
5e8686
 
5e8686
 % currentuser/systemparams creates and returns a dictionary in the
5e8686
 % current VM.  The easiest way to make this work is to copy any composite
5e8686
@@ -101,7 +101,7 @@ level2dict begin
5e8686
     1 index length string exch .setglobal
5e8686
     copy exch not { readonly } if
5e8686
   } if
5e8686
-} .bind def
5e8686
+} .bind odef
5e8686
 
5e8686
 % Some user parameters are managed entirely at the PostScript level.
5e8686
 % We take care of that here.
5e8686
@@ -345,13 +345,13 @@ end
5e8686
   } ifelse
5e8686
 } .bind def
5e8686
 /ProcessComment //null .definepsuserparam
5e8686
-psuserparams /ProcessComment {.checkprocesscomment} put
5e8686
+psuserparams /ProcessComment {//.checkprocesscomment exec} put
5e8686
 (%ProcessComment) cvn {
5e8686
   /ProcessComment getuserparam
5e8686
   dup //null eq { pop pop pop } { exec } ifelse
5e8686
 } bind def
5e8686
 /ProcessDSCComment //null .definepsuserparam
5e8686
-psuserparams /ProcessDSCComment {.checkprocesscomment} put
5e8686
+psuserparams /ProcessDSCComment {//.checkprocesscomment exec} put
5e8686
 /.loadingfont //false def
5e8686
 (%ProcessDSCComment) cvn {
5e8686
   /ProcessDSCComment getuserparam
5e8686
@@ -556,7 +556,8 @@ end		% serverdict
5e8686
 % Note that statusdict must be allocated in local VM.
5e8686
 % We don't bother with many of these yet.
5e8686
 
5e8686
-/.dict1 { exch mark 3 1 roll .dicttomark } bind def
5e8686
+% convenience function to make a dictionary from an object and a key
5e8686
+/.pair2dict { exch mark 3 1 roll .dicttomark } bind def
5e8686
 
5e8686
 currentglobal //false setglobal 25 dict exch setglobal begin
5e8686
 currentsystemparams
5e8686
@@ -569,11 +570,11 @@ systemdict /buildtime dup load put
5e8686
 /checkpassword { .checkpassword 0 gt } bind def
5e8686
 dup /DoStartPage known
5e8686
  { /dostartpage { /DoStartPage getsystemparam } bind def
5e8686
-   /setdostartpage { /DoStartPage .dict1 setsystemparams } bind def
5e8686
+   /setdostartpage { /DoStartPage //.pair2dict exec setsystemparams } bind def
5e8686
  } if
5e8686
 dup /StartupMode known
5e8686
  { /dosysstart { /StartupMode getsystemparam 0 ne } bind def
5e8686
-   /setdosysstart { { 1 } { 0 } ifelse /StartupMode .dict1 setsystemparams } bind def
5e8686
+   /setdosysstart { { 1 } { 0 } ifelse /StartupMode //.pair2dict exec setsystemparams } bind def
5e8686
  } if
5e8686
 %****** Setting jobname is supposed to set userparams.JobName, too.
5e8686
 /jobname { /JobName getuserparam } bind def
5e8686
@@ -581,7 +582,7 @@ dup /StartupMode known
5e8686
 /ramsize { /RamSize getsystemparam } bind def
5e8686
 /realformat 1 index /RealFormat get def
5e8686
 dup /PrinterName known
5e8686
- { /setprintername { /PrinterName .dict1 setsystemparams } bind def
5e8686
+ { /setprintername { /PrinterName //.pair2dict exec setsystemparams } bind def
5e8686
  } if
5e8686
 /printername
5e8686
  { currentsystemparams /PrinterName .knownget not { () } if exch copy
5e8686
@@ -617,18 +618,18 @@ currentuserparams /WaitTimeout known
5e8686
    /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
5e8686
  } bind def
5e8686
 /.setpagesize
5e8686
- { 2 copy 2 array astore /PageSize .dict1 { setpagedevice } stopped {
5e8686
+ { 2 copy 2 array astore /PageSize //.pair2dict exec { setpagedevice } stopped {
5e8686
      pop	% the setpagedevice dict
5e8686
      /setpagesize $error /errorname get signalerror
5e8686
    } {
5e8686
      pop pop	% success -- pop the arguments
5e8686
    } ifelse
5e8686
  } bind def
5e8686
-/setduplexmode { /Duplex .dict1 setpagedevice } bind def
5e8686
+/setduplexmode { /Duplex //.pair2dict exec setpagedevice } bind def
5e8686
 /setmargins
5e8686
- { exch 2 array astore /Margins .dict1 setpagedevice
5e8686
+ { exch 2 array astore /Margins //.pair2dict exec setpagedevice
5e8686
  } bind def
5e8686
-/setpagemargin { 0 2 array astore /PageOffset .dict1 setpagedevice } bind def
5e8686
+/setpagemargin { 0 2 array astore /PageOffset //.pair2dict exec setpagedevice } bind def
5e8686
 /setpageparams
5e8686
  { mark /PageSize 6 -2 roll
5e8686
    4 index 1 and ORIENT1 { 1 } { 0 } ifelse ne { exch } if 2 array astore
5e8686
@@ -642,7 +643,7 @@ currentuserparams /WaitTimeout known
5e8686
    {
5e8686
       /setresolution /typecheck signalerror
5e8686
    } if
5e8686
-   dup 2 array astore /HWResolution .dict1 { setpagedevice } stopped {
5e8686
+   dup 2 array astore /HWResolution //.pair2dict exec { setpagedevice } stopped {
5e8686
      pop /setresolution $error /errorname get signalerror
5e8686
    } if
5e8686
  } bind def
5e8686
@@ -1254,3 +1255,10 @@ def
5e8686
 %END TN 5044 psuedo-ops
5e8686
 
5e8686
 end				% level2dict
5e8686
+
5e8686
+% undefine things defined in this file and not referenced elsewhere
5e8686
+[
5e8686
+    /.checkprocesscomment
5e8686
+    /.pair2dict
5e8686
+]
5e8686
+{level2dict exch .forceundef} forall
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From 932f4106a00e99e4ee32dcc02e57d3636f383ea1 Mon Sep 17 00:00:00 2001
5e8686
From: Nancy Durgin <nancy.durgin@artifex.com>
5e8686
Date: Wed, 28 Nov 2018 10:09:01 -0800
5e8686
Subject: [PATCH 4/6] Undef internal functions from level2dict
5e8686
5e8686
---
5e8686
 Resource/Init/gs_lev2.ps | 6 ++++--
5e8686
 1 file changed, 4 insertions(+), 2 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_lev2.ps b/Resource/Init/gs_lev2.ps
5e8686
index e6f0645..7638f2a 100644
5e8686
--- a/Resource/Init/gs_lev2.ps
5e8686
+++ b/Resource/Init/gs_lev2.ps
5e8686
@@ -117,7 +117,7 @@ counttomark 2 idiv {
5e8686
 } repeat pop
5e8686
 /.definepsuserparam {		% <name> <value> .definepsuserparam -
5e8686
   psuserparams 3 copy pop
5e8686
-  type cvlit /.checkparamtype cvx 2 packedarray cvx put
5e8686
+  type cvlit //.checkparamtype /exec load 3 packedarray cvx put
5e8686
   userparams 3 1 roll put
5e8686
 } .bind def
5e8686
 end
5e8686
@@ -211,7 +211,7 @@ end
5e8686
      } forall
5e8686
    } if
5e8686
    /setsystemparams //pssystemparams mark exch {
5e8686
-     type cvlit /.checkparamtype cvx 2 packedarray cvx
5e8686
+     type cvlit //.checkparamtype /exec load 3 packedarray cvx
5e8686
    } forall .dicttomark .checksetparams
5e8686
         % Set the C-level system params.  If this succeeds, we know that
5e8686
         % the password check succeeded.
5e8686
@@ -1260,5 +1260,7 @@ end				% level2dict
5e8686
 [
5e8686
     /.checkprocesscomment
5e8686
     /.pair2dict
5e8686
+    /.setcolorrendering1
5e8686
+    /.checkparamtype
5e8686
 ]
5e8686
 {level2dict exch .forceundef} forall
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From e7ff64cf9b756278f19c87d295ee0fd95c955c05 Mon Sep 17 00:00:00 2001
5e8686
From: Nancy Durgin <nancy.durgin@artifex.com>
5e8686
Date: Wed, 23 Jan 2019 12:00:30 -0800
5e8686
Subject: [PATCH 5/6] Fixed bug caused by the way .checksetparams was undef'd
5e8686
5e8686
Previously, had undef'd it by making it an operator.
5e8686
Now just use an immediate reference and undef it in the gs_lev2.ps file.
5e8686
5e8686
This fixes bug introduced in commit fe4c47d8e25d6366ecbb5ff487348148b908a89e.
5e8686
5e8686
Undef'ing .checksetparams by making it an operator doesn't work right because
5e8686
errors report .checksetparams as the offending function instead of
5e8686
the operator that uses it (setsystemparams in this case).
5e8686
5e8686
This caused an error in file /tests_private/ps/ps3cet/27-09.PS on page 3,
5e8686
where it reports the offending function of some error-handling tests.
5e8686
Reporting function should be 'setsystemparams', not '.checksetparams' on
5e8686
this page.
5e8686
---
5e8686
 Resource/Init/gs_init.ps | 1 -
5e8686
 Resource/Init/gs_lev2.ps | 7 ++++---
5e8686
 2 files changed, 4 insertions(+), 4 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
5e8686
index e915f11..a2503f1 100644
5e8686
--- a/Resource/Init/gs_init.ps
5e8686
+++ b/Resource/Init/gs_init.ps
5e8686
@@ -2278,7 +2278,6 @@ SAFER { .setsafeglobal } if
5e8686
       /.setuserparams2
5e8686
       /.startjob
5e8686
       /.checkFilePermitparams
5e8686
-      /.checksetparams
5e8686
       /.copyparam
5e8686
       /.setpagesize
5e8686
 
5e8686
diff --git a/Resource/Init/gs_lev2.ps b/Resource/Init/gs_lev2.ps
5e8686
index 7638f2a..de1cc94 100644
5e8686
--- a/Resource/Init/gs_lev2.ps
5e8686
+++ b/Resource/Init/gs_lev2.ps
5e8686
@@ -64,7 +64,7 @@ level2dict begin
5e8686
       pop
5e8686
     } ifelse pop pop
5e8686
   } forall pop pop
5e8686
-} .bind odef
5e8686
+} .bind def
5e8686
 
5e8686
 % currentuser/systemparams creates and returns a dictionary in the
5e8686
 % current VM.  The easiest way to make this work is to copy any composite
5e8686
@@ -129,7 +129,7 @@ end
5e8686
 /.setuserparams2 {
5e8686
         % Check that we will be able to set the PostScript-level
5e8686
         % user parameters.
5e8686
-  /setuserparams /psuserparams .systemvar .checksetparams
5e8686
+  /setuserparams /psuserparams .systemvar //.checksetparams exec
5e8686
         % Set the C-level user params.  If this succeeds, we know that
5e8686
         % the password check succeeded.
5e8686
   dup .setuserparams
5e8686
@@ -212,7 +212,7 @@ end
5e8686
    } if
5e8686
    /setsystemparams //pssystemparams mark exch {
5e8686
      type cvlit //.checkparamtype /exec load 3 packedarray cvx
5e8686
-   } forall .dicttomark .checksetparams
5e8686
+   } forall .dicttomark //.checksetparams exec
5e8686
         % Set the C-level system params.  If this succeeds, we know that
5e8686
         % the password check succeeded.
5e8686
    dup .setsystemparams
5e8686
@@ -1262,5 +1262,6 @@ end				% level2dict
5e8686
     /.pair2dict
5e8686
     /.setcolorrendering1
5e8686
     /.checkparamtype
5e8686
+    /.checksetparams
5e8686
 ]
5e8686
 {level2dict exch .forceundef} forall
5e8686
-- 
5e8686
2.20.1
5e8686
5e8686
5e8686
From 4ec9ca74bed49f2a82acb4bf430eae0d8b3b75c9 Mon Sep 17 00:00:00 2001
5e8686
From: Ray Johnston <ray.johnston@artifex.com>
5e8686
Date: Thu, 31 Jan 2019 11:31:30 -0800
5e8686
Subject: [PATCH 6/6] Hide pdfdict and GS_PDF_ProcSet (internal stuff for the
5e8686
 PDF interp).
5e8686
5e8686
We now keep GS_PDF_ProcSet in pdfdict, and immediately bind pdfdict
5e8686
where needed so we can undef it after the last PDF interp file has
5e8686
run (pdf_sec.ps).
5e8686
---
5e8686
 Resource/Init/pdf_base.ps | 11 ++++----
5e8686
 Resource/Init/pdf_draw.ps | 59 +++++++++++++++++++--------------------
5e8686
 Resource/Init/pdf_font.ps |  9 +++---
5e8686
 Resource/Init/pdf_main.ps | 25 +++++++++--------
5e8686
 Resource/Init/pdf_ops.ps  | 11 ++++----
5e8686
 Resource/Init/pdf_sec.ps  |  4 ++-
5e8686
 6 files changed, 60 insertions(+), 59 deletions(-)
5e8686
5e8686
diff --git a/Resource/Init/pdf_base.ps b/Resource/Init/pdf_base.ps
5e8686
index c62ac0e..d3c3a5f 100644
5e8686
--- a/Resource/Init/pdf_base.ps
5e8686
+++ b/Resource/Init/pdf_base.ps
5e8686
@@ -23,7 +23,6 @@
5e8686
 
5e8686
 /.setlanguagelevel where { pop 2 .setlanguagelevel } if
5e8686
 .currentglobal //true .setglobal
5e8686
-/pdfdict where { pop } { /pdfdict 100 dict def } ifelse
5e8686
 pdfdict begin
5e8686
 
5e8686
 % Define the name interpretation dictionary for reading values.
5e8686
@@ -130,11 +129,11 @@ currentdict /num-chars-dict .undef
5e8686
 
5e8686
 /.pdfexectoken {		% <count> <opdict> <exectoken> .pdfexectoken ?
5e8686
   PDFDEBUG {
5e8686
-    pdfdict /PDFSTEPcount known not { pdfdict /PDFSTEPcount 1 .forceput } executeonly if
5e8686
+    //pdfdict /PDFSTEPcount known not { //pdfdict /PDFSTEPcount 1 .forceput } executeonly if
5e8686
     PDFSTEP {
5e8686
-      pdfdict /PDFtokencount 2 copy .knownget { 1 add } { 1 } ifelse .forceput
5e8686
+      //pdfdict /PDFtokencount 2 copy .knownget { 1 add } { 1 } ifelse .forceput
5e8686
       PDFSTEPcount 1 gt {
5e8686
-        pdfdict /PDFSTEPcount PDFSTEPcount 1 sub .forceput
5e8686
+        //pdfdict /PDFSTEPcount PDFSTEPcount 1 sub .forceput
5e8686
       } executeonly
5e8686
       {
5e8686
         dup ==only
5e8686
@@ -142,10 +141,10 @@ currentdict /num-chars-dict .undef
5e8686
         ( ? ) print flush 1 //false .outputpage
5e8686
         (%stdin) (r) file 255 string readline {
5e8686
           token {
5e8686
-            exch pop pdfdict /PDFSTEPcount 3 -1 roll .forceput
5e8686
+            exch pop //pdfdict /PDFSTEPcount 3 -1 roll .forceput
5e8686
           } executeonly
5e8686
           {
5e8686
-            pdfdict /PDFSTEPcount 1 .forceput
5e8686
+            //pdfdict /PDFSTEPcount 1 .forceput
5e8686
           } executeonly ifelse % token
5e8686
         } {
5e8686
           pop /PDFSTEP //false def	 % EOF on stdin
5e8686
diff --git a/Resource/Init/pdf_draw.ps b/Resource/Init/pdf_draw.ps
5e8686
index d743ae1..1add3f7 100644
5e8686
--- a/Resource/Init/pdf_draw.ps
5e8686
+++ b/Resource/Init/pdf_draw.ps
5e8686
@@ -18,8 +18,7 @@
5e8686
 
5e8686
 /.setlanguagelevel where { pop 2 .setlanguagelevel } if
5e8686
 .currentglobal //true .setglobal
5e8686
-/pdfdict where { pop } { /pdfdict 100 dict def } ifelse
5e8686
-GS_PDF_ProcSet begin
5e8686
+/GS_PDF_ProcSet load begin
5e8686
 pdfdict begin
5e8686
 
5e8686
 % For simplicity, we use a single interpretation dictionary for all
5e8686
@@ -113,7 +112,7 @@ pdfdict begin
5e8686
 
5e8686
 /resolvefunction {	% <fndict> resolvefunction <function>
5e8686
   .resolvefn
5e8686
-  PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%Function: ) print dup === flush } if } if
5e8686
+  PDFDEBUG { //pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%Function: ) print dup === flush } if } if
5e8686
 } bind executeonly def
5e8686
 
5e8686
 /resolvefnproc {	% <fndict> resolvefnproc <proc>
5e8686
@@ -1073,7 +1072,7 @@ currentdict end readonly def
5e8686
 %% finished running the PaintProc.
5e8686
 
5e8686
 /.actual_pdfpaintproc {         % <patdict> <resdict> .pdfpaintproc -
5e8686
-  PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%Begin PaintProc) print dup === flush } if } if
5e8686
+  PDFDEBUG { //pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%Begin PaintProc) print dup === flush } if } if
5e8686
   PDFfile fileposition 3 1 roll
5e8686
   q
5e8686
   1 index /PaintType oget 1 eq {
5e8686
@@ -1108,21 +1107,21 @@ currentdict end readonly def
5e8686
       Q
5e8686
     }{
5e8686
       (\n   **** Error: File has unbalanced q/Q operators \(too many Q's\)\n               Output may be incorrect.\n)
5e8686
-      pdfdict /.Qqwarning_issued .knownget
5e8686
+      //pdfdict /.Qqwarning_issued .knownget
5e8686
       {
5e8686
         {
5e8686
           pop
5e8686
         }
5e8686
         {
5e8686
-          currentglobal pdfdict gcheck .setglobal
5e8686
-          pdfdict /.Qqwarning_issued //true .forceput
5e8686
+          currentglobal //pdfdict gcheck .setglobal
5e8686
+          //pdfdict /.Qqwarning_issued //true .forceput
5e8686
           .setglobal
5e8686
           pdfformaterror
5e8686
         } executeonly ifelse
5e8686
       }
5e8686
       {
5e8686
-        currentglobal pdfdict gcheck .setglobal
5e8686
-        pdfdict /.Qqwarning_issued //true .forceput
5e8686
+        currentglobal //pdfdict gcheck .setglobal
5e8686
+        //pdfdict /.Qqwarning_issued //true .forceput
5e8686
         .setglobal
5e8686
         pdfformaterror
5e8686
       } executeonly ifelse
5e8686
@@ -1131,21 +1130,21 @@ currentdict end readonly def
5e8686
   } loop
5e8686
   {
5e8686
     (\n   **** Error: File has unbalanced q/Q operators \(too many q's\)\n               Output may be incorrect.\n)
5e8686
-    pdfdict /.Qqwarning_issued .knownget
5e8686
+    //pdfdict /.Qqwarning_issued .knownget
5e8686
     {
5e8686
       {
5e8686
         pop
5e8686
       }
5e8686
       {
5e8686
-        currentglobal pdfdict gcheck .setglobal
5e8686
-        pdfdict /.Qqwarning_issued //true .forceput
5e8686
+        currentglobal //pdfdict gcheck .setglobal
5e8686
+        //pdfdict /.Qqwarning_issued //true .forceput
5e8686
         .setglobal
5e8686
         pdfformaterror
5e8686
       } executeonly ifelse
5e8686
     }
5e8686
     {
5e8686
-      currentglobal pdfdict gcheck .setglobal
5e8686
-      pdfdict /.Qqwarning_issued //true .forceput
5e8686
+      currentglobal //pdfdict gcheck .setglobal
5e8686
+      //pdfdict /.Qqwarning_issued //true .forceput
5e8686
       .setglobal
5e8686
       pdfformaterror
5e8686
     } executeonly ifelse
5e8686
@@ -1156,7 +1155,7 @@ currentdict end readonly def
5e8686
   /pdfemptycount exch def
5e8686
 
5e8686
   Q
5e8686
-  PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%End PaintProc) print dup === flush } if } if
5e8686
+  PDFDEBUG { //pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%End PaintProc) print dup === flush } if } if
5e8686
   PDFfile exch setfileposition
5e8686
 } bind executeonly odef
5e8686
 
5e8686
@@ -1227,7 +1226,7 @@ currentdict end readonly def
5e8686
   ] cvx put
5e8686
   dup /BBox 2 copy knownoget { normrect FixPatternBBox put } { pop pop } ifelse
5e8686
   dup /.pattern_uses_transparency  1 index patternusestransparency put
5e8686
-  PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%Pattern: ) print dup === flush } if } if
5e8686
+  PDFDEBUG { //pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%Pattern: ) print dup === flush } if } if
5e8686
 } bind executeonly def
5e8686
 
5e8686
 /ignore_color_op  (   **** Error: Ignoring a color operation in a cached context.\n               Output may be incorrect.\n) readonly def
5e8686
@@ -2348,16 +2347,16 @@ currentdict /last-ditch-bpc-csp undef
5e8686
 } bind executeonly def
5e8686
 
5e8686
 /IncrementAppearanceNumber {
5e8686
-  pdfdict /AppearanceNumber .knownget {
5e8686
-    1 add pdfdict /AppearanceNumber 3 -1 roll .forceput
5e8686
+  //pdfdict /AppearanceNumber .knownget {
5e8686
+    1 add //pdfdict /AppearanceNumber 3 -1 roll .forceput
5e8686
   } executeonly
5e8686
   {
5e8686
-    pdfdict /AppearanceNumber 0 .forceput
5e8686
+    //pdfdict /AppearanceNumber 0 .forceput
5e8686
   } executeonly ifelse
5e8686
 }bind executeonly odef
5e8686
 
5e8686
 /MakeAppearanceName {
5e8686
-  pdfdict /AppearanceNumber get
5e8686
+  //pdfdict /AppearanceNumber get
5e8686
   10 string cvs
5e8686
   dup length 10 add string dup 0 (\{FormName) putinterval
5e8686
   dup 3 -1 roll
5e8686
@@ -2378,17 +2377,17 @@ currentdict /last-ditch-bpc-csp undef
5e8686
   gsave initclip
5e8686
   MakeNewAppearanceName
5e8686
   .pdfFormName
5e8686
-  pdfdict /.PreservePDFForm known {pdfdict /.PreservePDFForm get} {//false}ifelse exch
5e8686
-  pdfdict /.PreservePDFForm true .forceput
5e8686
+  //pdfdict /.PreservePDFForm known {//pdfdict /.PreservePDFForm get} {//false}ifelse exch
5e8686
+  //pdfdict /.PreservePDFForm true .forceput
5e8686
   DoForm
5e8686
-  pdfdict /.PreservePDFForm 3 -1 roll .forceput
5e8686
+  //pdfdict /.PreservePDFForm 3 -1 roll .forceput
5e8686
   grestore
5e8686
 } bind executeonly odef
5e8686
 
5e8686
 /DoForm {
5e8686
   %% save the current value, if its true we will set it to false later, in order
5e8686
   %% to prevent us preserving Forms which are used *from* an annotation /Appearance.
5e8686
-  pdfdict /.PreservePDFForm known {pdfdict /.PreservePDFForm get} {//false}ifelse exch
5e8686
+  //pdfdict /.PreservePDFForm known {//pdfdict /.PreservePDFForm get} {//false}ifelse exch
5e8686
 
5e8686
   %% We may alter the Default* colour spaces, if the Resources
5e8686
   %% ColorSpace entry contains one of them. But we don't want that
5e8686
@@ -2503,13 +2502,13 @@ currentdict /last-ditch-bpc-csp undef
5e8686
   pdfemptycount countdictstack 3 -1 roll
5e8686
   /pdfemptycount count 4 sub store
5e8686
 
5e8686
-  pdfdict /.PreservePDFForm known {pdfdict /.PreservePDFForm get}{//false} ifelse
5e8686
+  //pdfdict /.PreservePDFForm known {//pdfdict /.PreservePDFForm get}{//false} ifelse
5e8686
   {
5e8686
     %% We must *not* preserve any subsidiary forms (curently at least) as PDF
5e8686
     %% form preservation doesn't really work. This is used just for Annotation
5e8686
     %% Appearances currently, and if they should happen to use a form, we do not
5e8686
     %% want to preserve it.
5e8686
-    pdfdict /.PreservePDFForm false .forceput
5e8686
+    //pdfdict /.PreservePDFForm false .forceput
5e8686
     /q cvx /execform cvx 5 -2 roll
5e8686
   } executeonly
5e8686
   {
5e8686
@@ -2542,7 +2541,7 @@ currentdict /last-ditch-bpc-csp undef
5e8686
     saved_DCMYK /DefaultCMYK exch /ColorSpace defineresource pop
5e8686
     end
5e8686
   } if
5e8686
-  pdfdict /.PreservePDFForm 3 -1 roll .forceput
5e8686
+  //pdfdict /.PreservePDFForm 3 -1 roll .forceput
5e8686
 } bind executeonly odef
5e8686
 
5e8686
 /_dops_save 1 array def
5e8686
@@ -2701,13 +2700,13 @@ drawopdict begin
5e8686
     % Start by getting the object number for a Form XObject
5e8686
     dup Page /XObject obj_get dup 0 eq not {
5e8686
       % Now get the recording dictionary and see if that object number has been seen
5e8686
-      pdfdict /Recursive_XObject_D get 1 index known {
5e8686
+      //pdfdict /Recursive_XObject_D get 1 index known {
5e8686
         (   **** Error: Recursive XObject detected, ignoring ") print 1 index 256 string cvs print (", object number ) print 256 string cvs print (\n) print
5e8686
         (               Output may be incorrect.\n) pdfformaterror
5e8686
         //false
5e8686
       }{
5e8686
         % We haven't seen it yet, so record it.
5e8686
-        pdfdict /Recursive_XObject_D get 1 index null put
5e8686
+        //pdfdict /Recursive_XObject_D get 1 index null put
5e8686
         3 1 roll
5e8686
         //true
5e8686
       }ifelse
5e8686
@@ -2745,7 +2744,7 @@ drawopdict begin
5e8686
         (               Output may be incorrect.\n) pdfformaterror
5e8686
       } ifelse
5e8686
       PDFfile exch setfileposition
5e8686
-      pdfdict /Recursive_XObject_D get exch undef
5e8686
+      //pdfdict /Recursive_XObject_D get exch undef
5e8686
     }{
5e8686
       % Otherwise ignore it and tidy up the stacks
5e8686
       pop pop
5e8686
diff --git a/Resource/Init/pdf_font.ps b/Resource/Init/pdf_font.ps
5e8686
index 46408f9..275b659 100644
5e8686
--- a/Resource/Init/pdf_font.ps
5e8686
+++ b/Resource/Init/pdf_font.ps
5e8686
@@ -37,8 +37,7 @@
5e8686
 
5e8686
 /.setlanguagelevel where { pop 2 .setlanguagelevel } if
5e8686
 .currentglobal //true .setglobal
5e8686
-/pdfdict where { pop } { /pdfdict 100 dict def } ifelse
5e8686
-GS_PDF_ProcSet begin
5e8686
+/GS_PDF_ProcSet load begin	% from userdict at this point
5e8686
 pdfdict begin
5e8686
 
5e8686
 % We cache the PostScript font in an additional element of the
5e8686
@@ -1219,11 +1218,11 @@ currentdict /eexec_pdf_param_dict .undef
5e8686
             .pdfruncontext
5e8686
             countdictstack BuildCharDictDepth sub
5e8686
             {
5e8686
-              pdfdict /.Qqwarning_issued .knownget {not}{//true} ifelse
5e8686
+              //pdfdict /.Qqwarning_issued .knownget {not}{//true} ifelse
5e8686
               {
5e8686
                 (\n   **** Warning: Type 3 glyph has unbalanced q/Q operators \(too many q's\)\n               Output may be incorrect.\n)
5e8686
                 pdfformatwarning
5e8686
-                pdfdict /.Qqwarning_issued //true .forceput
5e8686
+                //pdfdict /.Qqwarning_issued //true .forceput
5e8686
               } executeonly if
5e8686
               Q
5e8686
             } repeat
5e8686
@@ -2334,7 +2333,7 @@ currentdict /bndef undef
5e8686
   dup //null eq
5e8686
   {pop}
5e8686
   {
5e8686
-    pdfdict /InputPDFFileName .knownget {.CRCHashFilenameAndObject} if
5e8686
+    //pdfdict /InputPDFFileName .knownget {.CRCHashFilenameAndObject} if
5e8686
     exch dup /.OrigUniqueIDXUID .knownget not
5e8686
     {
5e8686
       dup /XUID .knownget not
5e8686
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
5e8686
index dd1480b..e44288e 100644
5e8686
--- a/Resource/Init/pdf_main.ps
5e8686
+++ b/Resource/Init/pdf_main.ps
5e8686
@@ -18,8 +18,9 @@
5e8686
 
5e8686
 /.setlanguagelevel where { pop 2 .setlanguagelevel } if
5e8686
 .currentglobal //true .setglobal
5e8686
-/pdfdict where { pop } { /pdfdict 100 dict def } ifelse
5e8686
 pdfdict begin
5e8686
+/GS_PDF_ProcSet dup load def	% keep in pdfdict to hide it
5e8686
+userdict /GS_PDF_ProcSet undef
5e8686
 
5e8686
 % Patch in an obsolete variable used by some third-party software.
5e8686
 /#? //false def
5e8686
@@ -304,8 +305,8 @@ currentdict /runpdfstring .undef
5e8686
    /Page //null def
5e8686
    /DSCPageCount 0 def
5e8686
    /PDFSave //null def
5e8686
-   GS_PDF_ProcSet begin
5e8686
-   pdfdict begin
5e8686
+   //pdfdict /GS_PDF_ProcSet get begin
5e8686
+   //pdfdict begin
5e8686
    pdfopen begin
5e8686
    /CumulativePageCount currentpagedevice /PageCount get def
5e8686
 } bind executeonly def
5e8686
@@ -624,7 +625,7 @@ currentdict /runpdfstring .undef
5e8686
   %% copied to a temporary file) and store it in pdfdict. We will use this for
5e8686
   %% hashing fonts to detect if fonts with the same name are from different files.
5e8686
   %%
5e8686
-  dup currentglobal exch true setglobal .getfilename exch setglobal /InputPDFFileName exch pdfdict 3 1 roll .forceput
5e8686
+  dup currentglobal exch true setglobal .getfilename exch setglobal /InputPDFFileName exch //pdfdict 3 1 roll .forceput
5e8686
 
5e8686
   //runpdfbegin exec
5e8686
   //pdf_collection_files exec
5e8686
@@ -1390,7 +1391,7 @@ currentdict /xref-char-dict undef
5e8686
 } bind executeonly def
5e8686
 
5e8686
 /pdfopenfile {		% <file> pdfopenfile <dict>
5e8686
-   pdfdict readonly pop		% can't do it any earlier than this
5e8686
+   //pdfdict readonly pop		% can't do it any earlier than this
5e8686
    32 dict begin
5e8686
    /LocalResources 0 dict def
5e8686
    /DefaultQstate //null def	% establish binding
5e8686
@@ -2684,21 +2685,21 @@ currentdict /PDF2PS_matrix_key undef
5e8686
     StreamRunAborted not {
5e8686
       (\n   **** Error: File has unbalanced q/Q operators \(too many q's\)\n               Output may be incorrect.\n)
5e8686
 
5e8686
-      pdfdict /.Qqwarning_issued .knownget
5e8686
+      //pdfdict /.Qqwarning_issued .knownget
5e8686
       {
5e8686
         {
5e8686
           pop
5e8686
         }
5e8686
         {
5e8686
-          currentglobal pdfdict gcheck .setglobal
5e8686
-          pdfdict /.Qqwarning_issued //true .forceput
5e8686
+          currentglobal //pdfdict gcheck .setglobal
5e8686
+          //pdfdict /.Qqwarning_issued //true .forceput
5e8686
           .setglobal
5e8686
           pdfformaterror
5e8686
         } executeonly ifelse
5e8686
       }
5e8686
       {
5e8686
-        currentglobal pdfdict gcheck .setglobal
5e8686
-        pdfdict /.Qqwarning_issued //true .forceput
5e8686
+        currentglobal //pdfdict gcheck .setglobal
5e8686
+        //pdfdict /.Qqwarning_issued //true .forceput
5e8686
         .setglobal
5e8686
         pdfformaterror
5e8686
       } executeonly ifelse
5e8686
@@ -2710,8 +2711,8 @@ currentdict /PDF2PS_matrix_key undef
5e8686
   Repaired		% pass Repaired state around the restore
5e8686
   RepairedAnError
5e8686
   PDFSave restore
5e8686
-  currentglobal pdfdict gcheck .setglobal
5e8686
-  pdfdict /.Qqwarning_issued //false .forceput
5e8686
+  currentglobal //pdfdict gcheck .setglobal
5e8686
+  //pdfdict /.Qqwarning_issued //false .forceput
5e8686
   .setglobal
5e8686
   /RepairedAnError exch def
5e8686
   /Repaired exch def
5e8686
diff --git a/Resource/Init/pdf_ops.ps b/Resource/Init/pdf_ops.ps
5e8686
index aa09641..c2e7461 100644
5e8686
--- a/Resource/Init/pdf_ops.ps
5e8686
+++ b/Resource/Init/pdf_ops.ps
5e8686
@@ -24,6 +24,7 @@
5e8686
 systemdict /pdfmark known not
5e8686
  { userdict /pdfmark { cleartomark } bind executeonly put } if
5e8686
 
5e8686
+systemdict /pdfdict where { pop } { /pdfdict 100 dict put } ifelse
5e8686
 userdict /GS_PDF_ProcSet 256 dict dup begin
5e8686
 
5e8686
 % ---------------- Abbreviations ---------------- %
5e8686
@@ -174,21 +175,21 @@ currentdict /gput_always_allow .undef
5e8686
   {
5e8686
     (\n   **** Error: File has unbalanced q/Q operators \(too many Q's\)\n               Output may be incorrect.\n)
5e8686
 
5e8686
-    pdfdict /.Qqwarning_issued .knownget
5e8686
+    //pdfdict /.Qqwarning_issued .knownget
5e8686
     {
5e8686
       {
5e8686
         pop
5e8686
       }
5e8686
       {
5e8686
-        currentglobal pdfdict gcheck .setglobal
5e8686
-        pdfdict /.Qqwarning_issued //true .forceput
5e8686
+        currentglobal //pdfdict gcheck .setglobal
5e8686
+        //pdfdict /.Qqwarning_issued //true .forceput
5e8686
         .setglobal
5e8686
         pdfformaterror
5e8686
       } executeonly ifelse
5e8686
     }
5e8686
     {
5e8686
-      currentglobal pdfdict gcheck .setglobal
5e8686
-      pdfdict /.Qqwarning_issued //true .forceput
5e8686
+      currentglobal //pdfdict gcheck .setglobal
5e8686
+      //pdfdict /.Qqwarning_issued //true .forceput
5e8686
       .setglobal
5e8686
       pdfformaterror
5e8686
     } executeonly ifelse
5e8686
diff --git a/Resource/Init/pdf_sec.ps b/Resource/Init/pdf_sec.ps
5e8686
index 143efb7..a8e3d2e 100644
5e8686
--- a/Resource/Init/pdf_sec.ps
5e8686
+++ b/Resource/Init/pdf_sec.ps
5e8686
@@ -39,7 +39,6 @@
5e8686
 
5e8686
 /.setlanguagelevel where { pop 2 .setlanguagelevel } if
5e8686
 .currentglobal //true .setglobal
5e8686
-/pdfdict where { pop } { /pdfdict 100 dict def } ifelse
5e8686
 pdfdict begin
5e8686
 
5e8686
 % Older ghostscript versions do not have .pdftoken, so we use 'token' instead.
5e8686
@@ -748,4 +747,7 @@ currentdict /PDFScanRules_null undef
5e8686
  } bind executeonly def
5e8686
 
5e8686
 end			% pdfdict
5e8686
+
5e8686
+systemdict /pdfdict .forceundef		% hide pdfdict
5e8686
+
5e8686
 .setglobal
5e8686
-- 
5e8686
2.20.1
5e8686