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

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