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

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