Blame SOURCES/ghostscript-cve-2018-17961.patch

1164f7
From: Chris Liddell <chris.liddell@artifex.com>
1164f7
Date: Sat, 29 Sep 2018 14:34:55 +0000 (+0100)
1164f7
Subject: Bug 699816: Improve hiding of security critical custom operators
1164f7
1164f7
Bug 699816: Improve hiding of security critical custom operators
1164f7
1164f7
Make procedures that use .forceput/.forcedef/.forceundef into operators.
1164f7
1164f7
The result of this is that errors get reported against the "top" operator,
1164f7
rather than the "called" operator within the procedure.
1164f7
1164f7
For example:
1164f7
/myproc
1164f7
{
1164f7
  myop
1164f7
} bind def
1164f7
1164f7
If 'myop' throws an error, the error handler will be passed the 'myop'
1164f7
operator. Promoting 'myproc' to a operator means the error handler will be
1164f7
passed 'myproc'.
1164f7
1164f7
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=a54c9e61e7d02bbc620bcba9b1c208462a876afb
1164f7
1164f7
From: Chris Liddell <chris.liddell@artifex.com>
1164f7
Date: Wed, 10 Oct 2018 22:25:51 +0000 (+0100)
1164f7
Subject: Bug 699938: .loadfontloop must be an operator
1164f7
1164f7
Bug 699938: .loadfontloop must be an operator
1164f7
1164f7
In the fix for Bug 699816, I omitted to make .loadfontloop into an operator, to
1164f7
better hide .forceundef and .putgstringcopy.
1164f7
1164f7
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=a5a9bf8c6a63aa4ac6874234fe8cd63e72077291
1164f7
1164f7
From: Chris Liddell <chris.liddell@artifex.com>
1164f7
Date: Wed, 28 Nov 2018 17:12:08 +0000 (+0000)
1164f7
Subject: Bug 700290: Fix problems with DELAYBIND and font substitution
1164f7
1164f7
Bug 700290: Fix problems with DELAYBIND and font substitution
1164f7
1164f7
Judicious use of immediate evaluation for .setnativefontmapbuilt and
1164f7
.putgstringcopy to avoid problems with DELAYBIND
1164f7
1164f7
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=2756f0efae1d3966989b15a6526c5d80848b5015
1164f7
---
1164f7
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_diskn.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_diskn.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_diskn.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_diskn.ps	2018-12-10 14:51:03.208407266 +0100
1164f7
@@ -53,7 +53,7 @@ systemdict begin
1164f7
     exch .setglobal
1164f7
   }
1164f7
   if
1164f7
-} .bind executeonly def % must be bound and hidden for .forceput
1164f7
+} .bind executeonly odef % must be bound and hidden for .forceput
1164f7
 
1164f7
 % Modify .putdevparams to force regeneration of .searchabledevs list
1164f7
 /.putdevparams {
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_dps.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_dps.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_dps.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_dps.ps	2018-12-10 14:51:03.208407266 +0100
1164f7
@@ -71,7 +71,7 @@
1164f7
   //true .setglobal
1164f7
   //systemdict /savedinitialgstate gstate readonly put
1164f7
   .setglobal
1164f7
-} .bind def
1164f7
+} .bind executeonly odef % must be bound and hidden for .forceput
1164f7
 
1164f7
 % Initialize local dictionaries and gstate when creating a new context.
1164f7
 % Note that until this completes, we are in the anomalous situation of
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_fntem.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_fntem.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_fntem.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_fntem.ps	2018-12-10 14:51:03.209407249 +0100
1164f7
@@ -432,7 +432,7 @@ currentdict end def
1164f7
     exit
1164f7
   } loop
1164f7
   exch setglobal
1164f7
-} bind def
1164f7
+} .bind executeonly odef % must be bound and hidden for .forceput
1164f7
 
1164f7
 currentdict end /ProcSet defineresource pop
1164f7
 
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_fonts.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_fonts.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_fonts.ps.cve-2018-17961	2018-12-10 14:51:03.002410648 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_fonts.ps	2018-12-10 14:51:03.209407249 +0100
1164f7
@@ -375,7 +375,7 @@ FONTPATH length 0 eq { (%END FONTPATH) .
1164f7
 % and the access path.
1164f7
 /.setnativefontmapbuilt { % set whether we've been run
1164f7
   systemdict exch /.nativefontmapbuilt exch .forceput
1164f7
-} .bind executeonly def
1164f7
+} .bind executeonly odef
1164f7
 systemdict /NONATIVEFONTMAP known .setnativefontmapbuilt
1164f7
 /.buildnativefontmap {   % - .buildnativefontmap <bool>
1164f7
   QUIET not {
1164f7
@@ -404,7 +404,7 @@ systemdict /NONATIVEFONTMAP known .setna
1164f7
     } forall
1164f7
   } if
1164f7
   % record that we've been run
1164f7
-  //true .setnativefontmapbuilt
1164f7
+  //true //.setnativefontmapbuilt
1164f7
 } bind def
1164f7
 
1164f7
 % Create the dictionary that registers the .buildfont procedure
1164f7
@@ -1082,7 +1082,7 @@ $error /SubstituteFont { } put
1164f7
 
1164f7
                 % Check to make sure the font was actually loaded.
1164f7
         dup 3 index .fontknownget
1164f7
-         { dup /PathLoad 4 index //.putgstringcopy exec
1164f7
+         { dup /PathLoad 4 index //.putgstringcopy
1164f7
            4 1 roll pop pop pop //true exit
1164f7
          } if
1164f7
 
1164f7
@@ -1094,7 +1094,7 @@ $error /SubstituteFont { } put
1164f7
          {            % Stack: origfontname fontdirectory path filefontname
1164f7
            2 index 1 index .fontknownget
1164f7
             {   % Yes.  Stack: origfontname fontdirectory path filefontname fontdict
1164f7
-              dup 4 -1 roll /PathLoad exch //.putgstringcopy exec
1164f7
+              dup 4 -1 roll /PathLoad exch //.putgstringcopy
1164f7
                       % Stack: origfontname fontdirectory filefontname fontdict
1164f7
               3 -1 roll pop exch
1164f7
                       % Stack: origfontname fontdict filefontname
1164f7
@@ -1122,9 +1122,8 @@ $error /SubstituteFont { } put
1164f7
 
1164f7
     } loop              % end of loop
1164f7
 
1164f7
- } bind executeonly def % must be bound and hidden for .putgstringcopy
1164f7
-
1164f7
-currentdict /.putgstringcopy .undef
1164f7
+ } bind executeonly odef % must be bound and hidden for .putgstringcopy
1164f7
+currentdict /.putgstringcopy .forceundef
1164f7
 
1164f7
 % Define a procedure to load all known fonts.
1164f7
 % This isn't likely to be very useful.
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_lev2.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_lev2.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_lev2.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_lev2.ps	2018-12-10 14:51:03.210407233 +0100
1164f7
@@ -163,9 +163,10 @@ end
1164f7
         % Set them again to the new values.  From here on, we are safe,
1164f7
         % since a context switch will consult userparams.
1164f7
   .setuserparams
1164f7
-} .bind def
1164f7
+} .bind executeonly odef % must be bound and hidden for .forceput
1164f7
 /setuserparams {		% <dict> setuserparams -
1164f7
-    .setuserparams2
1164f7
+    {.setuserparams2} stopped
1164f7
+    {/setuserparams load $error /errorname get signalerror} if
1164f7
 } .bind odef
1164f7
 % Initialize user parameters managed here.
1164f7
 /JobName () .definepsuserparam
1164f7
@@ -414,7 +415,9 @@ psuserparams /ProcessDSCComment {.checkp
1164f7
 
1164f7
 % VMReclaim and VMThreshold are user parameters.
1164f7
 /setvmthreshold {		% <int> setvmthreshold -
1164f7
-  mark /VMThreshold 2 .argindex .dicttomark .setuserparams2 pop
1164f7
+  mark /VMThreshold 2 .argindex .dicttomark {.setuserparams2} stopped
1164f7
+  {pop /setvmthreshold load $error /errorname get signalerror}
1164f7
+  {pop} ifelse
1164f7
 } odef
1164f7
 /vmreclaim {			% <int> vmreclaim -
1164f7
   dup 0 gt {
1164f7
@@ -426,7 +429,9 @@ psuserparams /ProcessDSCComment {.checkp
1164f7
     ifelse
1164f7
   } {
1164f7
     % VMReclaim userparam controls enable/disable GC
1164f7
-    mark /VMReclaim 2 index .dicttomark .setuserparams2 pop
1164f7
+    mark /VMReclaim 2 index .dicttomark {.setuserparams2} stopped
1164f7
+    {pop /vmreclaim load $error /errorname get signalerror}
1164f7
+    {pop} ifelse
1164f7
   } ifelse
1164f7
 } odef
1164f7
 -1 setvmthreshold
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_pdfwr.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_pdfwr.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_pdfwr.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_pdfwr.ps	2018-12-10 14:51:03.210407233 +0100
1164f7
@@ -547,8 +547,7 @@ currentdict /.pdfmarkparams .undef
1164f7
   } {
1164f7
     pop
1164f7
   } ifelse
1164f7
-}
1164f7
-bind def
1164f7
+} .bind executeonly odef % must be bound and hidden for .forceput
1164f7
 
1164f7
 % Use the DSC processing hook to pass DSC comments to the driver.
1164f7
 % We use a pseudo-parameter named DSC whose value is an array:
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_setpd.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_setpd.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_setpd.ps.cve-2018-17961	2018-12-10 14:51:03.194407496 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_setpd.ps	2018-12-10 14:51:03.210407233 +0100
1164f7
@@ -544,6 +544,20 @@ NOMEDIAATTRS {
1164f7
 % in the <failed> dictionary with the policy value,
1164f7
 % and we replace the key in the <merged> dictionary with its prior value
1164f7
 % (or remove it if it had no prior value).
1164f7
+
1164f7
+% Making this an operator means we can properly hide
1164f7
+% the contents - specifically .forceput
1164f7
+/1Policy
1164f7
+{
1164f7
+  % Roll back the failed request to its previous status.
1164f7
+  SETPDDEBUG { (Rolling back.) = pstack flush } if
1164f7
+  3 index 2 index 3 -1 roll .forceput
1164f7
+  4 index 1 index .knownget
1164f7
+   { 4 index 3 1 roll .forceput }
1164f7
+   { 3 index exch .undef }
1164f7
+  ifelse
1164f7
+} bind executeonly odef
1164f7
+
1164f7
 /.policyprocs mark
1164f7
 % These procedures are called with the following on the stack:
1164f7
 %   <orig> <merged> <failed> <Policies> <key> <policy>
1164f7
@@ -567,14 +581,7 @@ NOMEDIAATTRS {
1164f7
         /setpagedevice .systemvar /configurationerror signalerror
1164f7
       } ifelse
1164f7
   } bind
1164f7
-  1 {		% Roll back the failed request to its previous status.
1164f7
-SETPDDEBUG { (Rolling back.) = pstack flush } if
1164f7
-        3 index 2 index 3 -1 roll .forceput
1164f7
-        4 index 1 index .knownget
1164f7
-         { 4 index 3 1 roll .forceput }
1164f7
-         { 3 index exch .undef }
1164f7
-        ifelse
1164f7
-  } .bind
1164f7
+  1 /1Policy load
1164f7
   7 {		% For PageSize only, just impose the request.
1164f7
         1 index /PageSize eq
1164f7
          { pop pop 1 index /PageSize 7 put }
1164f7
@@ -582,6 +589,8 @@ SETPDDEBUG { (Rolling back.) = pstack fl
1164f7
         ifelse
1164f7
   } bind
1164f7
 .dicttomark readonly def
1164f7
+currentdict /1Policy undef
1164f7
+
1164f7
 /.applypolicies		% <orig> <merged> <failed> .applypolicies
1164f7
                         %   <orig> <merged'> <failed'>
1164f7
  { 1 index /Policies get 1 index
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_typ32.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_typ32.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_typ32.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_typ32.ps	2018-12-10 14:51:03.211407216 +0100
1164f7
@@ -79,15 +79,19 @@ systemdict /.removeglyphs .undef
1164f7
 .dicttomark /ProcSet defineresource pop
1164f7
 
1164f7
 /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
1164f7
-.cidfonttypes begin
1164f7
-
1164f7
-4	% CIDFontType 4 = FontType 32
1164f7
-{ dup /FontType 32 .forceput
1164f7
+/CIDFontType4
1164f7
+{
1164f7
+  dup /FontType 32 .forceput
1164f7
   dup /CharStrings 20 dict .forceput
1164f7
   1 index exch .buildfont32 exch pop
1164f7
-} bind def
1164f7
+} .bind executeonly odef
1164f7
+.cidfonttypes begin
1164f7
+
1164f7
+
1164f7
+4 /CIDFontType4 load def % CIDFontType 4 = FontType 32
1164f7
 
1164f7
 end		% .cidfonttypes
1164f7
+currentdict /CIDFontType4 .forceundef
1164f7
 
1164f7
 % Define the BuildGlyph procedure.
1164f7
 % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
1164f7
diff -up ghostscript-9.07/Resource/Init/gs_type1.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/gs_type1.ps
1164f7
--- ghostscript-9.07/Resource/Init/gs_type1.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/gs_type1.ps	2018-12-10 14:51:03.211407216 +0100
1164f7
@@ -215,7 +215,7 @@ currentdict /closesourcedict .undef
1164f7
   } if
1164f7
   2 copy /WeightVector exch .forceput
1164f7
   .setweightvector
1164f7
-} .bind executeonly def
1164f7
+} .bind executeonly odef
1164f7
 end
1164f7
 
1164f7
 % Register the font types for definefont.
1164f7
diff -up ghostscript-9.07/Resource/Init/pdf_base.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/pdf_base.ps
1164f7
--- ghostscript-9.07/Resource/Init/pdf_base.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/pdf_base.ps	2018-12-10 14:51:03.211407216 +0100
1164f7
@@ -177,7 +177,7 @@ currentdict /num-chars-dict .undef
1164f7
       } ifelse
1164f7
     } ifelse
1164f7
   } ifelse
1164f7
-} bind def
1164f7
+} bind executeonly odef
1164f7
 /PDFScanRules_true << /PDFScanRules //true >> def
1164f7
 /PDFScanRules_null << /PDFScanRules //null >> def
1164f7
 /.pdfrun {			% <file> <opdict> .pdfrun -
1164f7
diff -up ghostscript-9.07/Resource/Init/pdf_draw.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/pdf_draw.ps
1164f7
--- ghostscript-9.07/Resource/Init/pdf_draw.ps.cve-2018-17961	2018-12-10 14:51:03.177407775 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/pdf_draw.ps	2018-12-10 14:51:03.212407200 +0100
1164f7
@@ -948,7 +948,7 @@ currentdict end readonly def
1164f7
   Q
1164f7
   PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%End PaintProc) print dup === flush } if } if
1164f7
   PDFfile exch setfileposition
1164f7
-} bdef
1164f7
+}bind executeonly odef
1164f7
 
1164f7
 /resolvepattern {	% <patternstreamdict> resolvepattern <patterndict>
1164f7
                 % Don't do the resolvestream now: just capture the data
1164f7
@@ -1809,7 +1809,7 @@ currentdict /last-ditch-bpc-csp undef
1164f7
   } if
1164f7
   pop
1164f7
   /pdfemptycount exch store
1164f7
-} bdef
1164f7
+} bind executeonly odef
1164f7
 
1164f7
 /_dops_save 1 array def
1164f7
 
1164f7
diff -up ghostscript-9.07/Resource/Init/pdf_font.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/pdf_font.ps
1164f7
--- ghostscript-9.07/Resource/Init/pdf_font.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/pdf_font.ps	2018-12-10 14:51:03.213407183 +0100
1164f7
@@ -641,7 +641,7 @@ currentdict end readonly def
1164f7
     } if
1164f7
   } if
1164f7
   pop pop pop
1164f7
-} bind def
1164f7
+} bind executeonly odef
1164f7
 
1164f7
 % ---------------- Descriptors ---------------- %
1164f7
 
1164f7
@@ -1097,7 +1097,7 @@ currentdict /eexec_pdf_param_dict .undef
1164f7
     } bdef
1164f7
     dup currentdict Encoding .processToUnicode
1164f7
     currentdict end .completefont exch pop
1164f7
-} bdef
1164f7
+} bind executeonly odef
1164f7
 /.adjustcharwidth {	% <wx> <wy> .adjustcharwidth <wx'> <wy'>
1164f7
   % Enforce the metrics, in glyph space, to the values found in the PDF Font object
1164f7
   % - force wy == 0 (assumed, and not stored in the PDF font)
1164f7
@@ -1794,7 +1794,7 @@ currentdict /CMap_read_dict undef
1164f7
     } if
1164f7
     /findresource cvx /undefined signalerror
1164f7
   } loop
1164f7
-} bdef
1164f7
+} bind executeonly odef
1164f7
 
1164f7
 /buildCIDType0 {	% <CIDFontType0-font-resource> buildCIDType0 <font>
1164f7
   dup /BaseFont get findCIDFont exch pop
1164f7
@@ -1964,7 +1964,7 @@ currentdict /CMap_read_dict undef
1164f7
   /Type0 //buildType0
1164f7
   /Type1 //buildType1
1164f7
   /MMType1 //buildType1
1164f7
-  /Type3 //buildType3
1164f7
+  /Type3 /buildType3 load
1164f7
   /TrueType //buildTrueType
1164f7
   /CIDFontType0 //buildCIDType0
1164f7
   /CIDFontType2 //buildCIDType2
1164f7
diff -up ghostscript-9.07/Resource/Init/pdf_main.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/pdf_main.ps
1164f7
--- ghostscript-9.07/Resource/Init/pdf_main.ps.cve-2018-17961	2018-12-10 14:51:03.168407922 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/pdf_main.ps	2018-12-10 14:51:03.213407183 +0100
1164f7
@@ -382,7 +382,7 @@ currentdict /runpdfstring .undef
1164f7
     } forall
1164f7
     pop
1164f7
   } ifelse
1164f7
-} bind def
1164f7
+} bind executeonly odef
1164f7
 
1164f7
 currentdict /pdf_collection_files .undef
1164f7
 
1164f7
@@ -1878,7 +1878,7 @@ currentdict /PDF2PS_matrix_key undef
1164f7
   Repaired		% pass Repaired state around the restore
1164f7
   PDFSave restore
1164f7
   /Repaired exch def
1164f7
-} bind def
1164f7
+} bind executeonly odef
1164f7
 
1164f7
 % Display the contents of a page (including annotations).
1164f7
 /showpagecontents {	% <pagedict> showpagecontents -
1164f7
diff -up ghostscript-9.07/Resource/Init/pdf_ops.ps.cve-2018-17961 ghostscript-9.07/Resource/Init/pdf_ops.ps
1164f7
--- ghostscript-9.07/Resource/Init/pdf_ops.ps.cve-2018-17961	2013-02-14 08:58:16.000000000 +0100
1164f7
+++ ghostscript-9.07/Resource/Init/pdf_ops.ps	2018-12-10 14:51:03.214407167 +0100
1164f7
@@ -128,7 +128,7 @@ nodict readonly pop
1164f7
   { (\n   **** File has unbalanced q/Q operators \(too many Q's\) ****\n)
1164f7
     pdfformaterror
1164f7
   } if
1164f7
-} bdef
1164f7
+} bind executeonly odef
1164f7
 
1164f7
 % Save PDF gstate
1164f7
 /qstate {       % - qstate <qstate>
1164f7
@@ -282,7 +282,7 @@ nodict readonly pop
1164f7
 } bdef
1164f7
 /ca { /FillConstantAlpha gput } bdef
1164f7
 /CA { /StrokeConstantAlpha gput } bdef
1164f7
-/SMask { /SoftMask gput } bdef
1164f7
+/SMask { /SoftMask gput } bind executeonly odef
1164f7
 /AIS { /AlphaIsShape gput } bdef
1164f7
 /BM {
1164f7
   /.setblendmode where {