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

6bfa55
From be86d2ff2f0f0ea0e365707f3be0fa0c9e7315ee Mon Sep 17 00:00:00 2001
6bfa55
From: Ray Johnston <ray.johnston@artifex.com>
6bfa55
Date: Mon, 18 Feb 2019 12:11:45 -0800
6bfa55
Subject: [PATCH 1/2] Bug 700599: Issue an error message if an ExtGstate is not
6bfa55
 found.
6bfa55
6bfa55
Previously, this was silently ignored. Only issue a single warning,
6bfa55
and respect PDFSTOPONERROR to prevent continuing with potentially
6bfa55
incorrect output.
6bfa55
6bfa55
Note that tests_private/pdf/uploads/bug696410.pdf also now gets this
6bfa55
error message (ExtGState" instead of ExtGState in object 10).
6bfa55
---
6bfa55
 Resource/Init/pdf_draw.ps | 11 ++++++++++-
6bfa55
 1 file changed, 10 insertions(+), 1 deletion(-)
6bfa55
6bfa55
diff --git a/Resource/Init/pdf_draw.ps b/Resource/Init/pdf_draw.ps
6bfa55
index 1add3f7..6a2773a 100644
6bfa55
--- a/Resource/Init/pdf_draw.ps
6bfa55
+++ b/Resource/Init/pdf_draw.ps
6bfa55
@@ -494,7 +494,16 @@ end
6bfa55
     dup {
6bfa55
       oforce exch gsparamdict exch .knownget { exec } { pop } ifelse
6bfa55
     } forall pop
6bfa55
-  } if
6bfa55
+  } {
6bfa55
+    //pdfdict /.gs_warning_issued known not {
6bfa55
+      (\n   **** Error 'gs' ignored -- ExtGState missing from Resources.\n)
6bfa55
+      pdfformaterror
6bfa55
+      (        Output may be incorrect.\n) pdfformaterror
6bfa55
+      //pdfdict /.gs_warning_issued //true .forceput
6bfa55
+      PDFSTOPONERROR { /gs /undefined signalerror } if
6bfa55
+    } if
6bfa55
+  }
6bfa55
+  ifelse
6bfa55
 } bind executeonly def
6bfa55
 
6bfa55
 % ------ Transparency support ------ %
6bfa55
-- 
6bfa55
2.20.1
6bfa55
6bfa55
6bfa55
From cd1b1cacadac2479e291efe611979bdc1b3bdb19 Mon Sep 17 00:00:00 2001
6bfa55
From: Ken Sharp <ken.sharp@artifex.com>
6bfa55
Date: Wed, 21 Aug 2019 10:10:51 +0100
6bfa55
Subject: [PATCH 2/2] PDF interpreter - review .forceput security
6bfa55
6bfa55
Bug #701450 "Safer Mode Bypass by .forceput Exposure in .pdfexectoken"
6bfa55
6bfa55
By abusing the error handler it was possible to get the PDFDEBUG portion
6bfa55
of .pdfexectoken, which uses .forceput left readable.
6bfa55
6bfa55
Add an executeonly appropriately to make sure that clause isn't readable
6bfa55
no mstter what.
6bfa55
6bfa55
Review all the uses of .forceput searching for similar cases, add
6bfa55
executeonly as required to secure those. All cases in the PostScript
6bfa55
support files seem to be covered already.
6bfa55
---
6bfa55
 Resource/Init/pdf_base.ps |  2 +-
6bfa55
 Resource/Init/pdf_draw.ps | 14 +++++++-------
6bfa55
 Resource/Init/pdf_font.ps | 23 ++++++++++++-----------
6bfa55
 Resource/Init/pdf_main.ps |  6 +++---
6bfa55
 Resource/Init/pdf_ops.ps  | 11 ++++++-----
6bfa55
 5 files changed, 29 insertions(+), 27 deletions(-)
6bfa55
6bfa55
diff --git a/Resource/Init/pdf_base.ps b/Resource/Init/pdf_base.ps
6bfa55
index d3c3a5f..5dabe4d 100644
6bfa55
--- a/Resource/Init/pdf_base.ps
6bfa55
+++ b/Resource/Init/pdf_base.ps
6bfa55
@@ -154,7 +154,7 @@ currentdict /num-chars-dict .undef
6bfa55
     {
6bfa55
       dup ==only () = flush
6bfa55
     } ifelse % PDFSTEP
6bfa55
-  } if % PDFDEBUG
6bfa55
+  } executeonly if % PDFDEBUG
6bfa55
   2 copy .knownget {
6bfa55
     exch pop exch pop exch pop exec
6bfa55
   } {
6bfa55
diff --git a/Resource/Init/pdf_draw.ps b/Resource/Init/pdf_draw.ps
6bfa55
index 6a2773a..068ba7c 100644
6bfa55
--- a/Resource/Init/pdf_draw.ps
6bfa55
+++ b/Resource/Init/pdf_draw.ps
6bfa55
@@ -501,8 +501,8 @@ end
6bfa55
       (        Output may be incorrect.\n) pdfformaterror
6bfa55
       //pdfdict /.gs_warning_issued //true .forceput
6bfa55
       PDFSTOPONERROR { /gs /undefined signalerror } if
6bfa55
-    } if
6bfa55
-  }
6bfa55
+    } executeonly if
6bfa55
+  } executeonly
6bfa55
   ifelse
6bfa55
 } bind executeonly def
6bfa55
 
6bfa55
@@ -1127,7 +1127,7 @@ currentdict end readonly def
6bfa55
           .setglobal
6bfa55
           pdfformaterror
6bfa55
         } executeonly ifelse
6bfa55
-      }
6bfa55
+      } executeonly
6bfa55
       {
6bfa55
         currentglobal //pdfdict gcheck .setglobal
6bfa55
         //pdfdict /.Qqwarning_issued //true .forceput
6bfa55
@@ -1135,8 +1135,8 @@ currentdict end readonly def
6bfa55
         pdfformaterror
6bfa55
       } executeonly ifelse
6bfa55
       end
6bfa55
-    } ifelse
6bfa55
-  } loop
6bfa55
+    } executeonly ifelse
6bfa55
+  } executeonly loop
6bfa55
   {
6bfa55
     (\n   **** Error: File has unbalanced q/Q operators \(too many q's\)\n               Output may be incorrect.\n)
6bfa55
     //pdfdict /.Qqwarning_issued .knownget
6bfa55
@@ -1150,14 +1150,14 @@ currentdict end readonly def
6bfa55
         .setglobal
6bfa55
         pdfformaterror
6bfa55
       } executeonly ifelse
6bfa55
-    }
6bfa55
+    } executeonly
6bfa55
     {
6bfa55
       currentglobal //pdfdict gcheck .setglobal
6bfa55
       //pdfdict /.Qqwarning_issued //true .forceput
6bfa55
       .setglobal
6bfa55
       pdfformaterror
6bfa55
     } executeonly ifelse
6bfa55
-  } if
6bfa55
+  } executeonly if
6bfa55
   pop
6bfa55
 
6bfa55
   % restore pdfemptycount
6bfa55
diff --git a/Resource/Init/pdf_font.ps b/Resource/Init/pdf_font.ps
6bfa55
index 8b8fef8..86b1870 100644
6bfa55
--- a/Resource/Init/pdf_font.ps
6bfa55
+++ b/Resource/Init/pdf_font.ps
6bfa55
@@ -677,7 +677,7 @@ currentdict end readonly def
6bfa55
                 currentglobal 2 index dup gcheck setglobal
6bfa55
                 /FontInfo 5 dict dup 5 1 roll .forceput
6bfa55
                 setglobal
6bfa55
-              } if
6bfa55
+              } executeonly if
6bfa55
               dup /GlyphNames2Unicode .knownget not {
6bfa55
                 //true                        % No existing G2U, make one
6bfa55
               } {
6bfa55
@@ -701,9 +701,9 @@ currentdict end readonly def
6bfa55
         } if
6bfa55
         PDFDEBUG {
6bfa55
           (.processToUnicode end) =
6bfa55
-        } if
6bfa55
-      } if
6bfa55
-    } stopped
6bfa55
+        } executeonly if
6bfa55
+      } executeonly if
6bfa55
+    } executeonly stopped
6bfa55
     {
6bfa55
       .dstackdepth 1 countdictstack 1 sub
6bfa55
       {pop end} for
6bfa55
@@ -1225,19 +1225,20 @@ currentdict /eexec_pdf_param_dict .undef
6bfa55
                 //pdfdict /.Qqwarning_issued //true .forceput
6bfa55
               } executeonly if
6bfa55
               Q
6bfa55
-            } repeat
6bfa55
+            } executeonly repeat
6bfa55
             Q
6bfa55
-          } PDFfile fileposition 2 .execn % Keep pdfcount valid.
6bfa55
+          } executeonly PDFfile fileposition 2 .execn % Keep pdfcount valid.
6bfa55
           PDFfile exch setfileposition
6bfa55
-        } ifelse
6bfa55
-      } {
6bfa55
+        } executeonly ifelse
6bfa55
+      } executeonly
6bfa55
+      {
6bfa55
         % PDF Type 3 fonts don't use .notdef
6bfa55
         % d1 implementation adjusts the width as needed
6bfa55
         0 0 0 0 0 0
6bfa55
         pdfopdict /d1 get exec
6bfa55
       } ifelse
6bfa55
       end end
6bfa55
-    } bdef
6bfa55
+    } executeonly bdef
6bfa55
     dup currentdict Encoding .processToUnicode
6bfa55
     currentdict end .completefont exch pop
6bfa55
 } bind executeonly odef
6bfa55
@@ -2022,9 +2023,9 @@ currentdict /CMap_read_dict undef
6bfa55
           (Will continue, but content may be missing.) = flush
6bfa55
         } ifelse
6bfa55
       } if
6bfa55
-    } if
6bfa55
+    } executeonly if
6bfa55
     /findresource cvx /undefined signalerror
6bfa55
-  } loop
6bfa55
+  } executeonly loop
6bfa55
 } bind executeonly odef
6bfa55
 
6bfa55
 /buildCIDType0 {	% <CIDFontType0-font-resource> buildCIDType0 <font>
6bfa55
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
6bfa55
index e44288e..ecde3d4 100644
6bfa55
--- a/Resource/Init/pdf_main.ps
6bfa55
+++ b/Resource/Init/pdf_main.ps
6bfa55
@@ -2696,15 +2696,15 @@ currentdict /PDF2PS_matrix_key undef
6bfa55
           .setglobal
6bfa55
           pdfformaterror
6bfa55
         } executeonly ifelse
6bfa55
-      }
6bfa55
+      } executeonly
6bfa55
       {
6bfa55
         currentglobal //pdfdict gcheck .setglobal
6bfa55
         //pdfdict /.Qqwarning_issued //true .forceput
6bfa55
         .setglobal
6bfa55
         pdfformaterror
6bfa55
       } executeonly ifelse
6bfa55
-    } if
6bfa55
-  } if
6bfa55
+    } executeonly if
6bfa55
+  } executeonly if
6bfa55
   pop
6bfa55
   count PDFexecstackcount sub { pop } repeat
6bfa55
   (after exec) VMDEBUG
6bfa55
diff --git a/Resource/Init/pdf_ops.ps b/Resource/Init/pdf_ops.ps
6bfa55
index c2e7461..12d5a66 100644
6bfa55
--- a/Resource/Init/pdf_ops.ps
6bfa55
+++ b/Resource/Init/pdf_ops.ps
6bfa55
@@ -186,14 +186,14 @@ currentdict /gput_always_allow .undef
6bfa55
         .setglobal
6bfa55
         pdfformaterror
6bfa55
       } executeonly ifelse
6bfa55
-    }
6bfa55
+    } executeonly
6bfa55
     {
6bfa55
       currentglobal //pdfdict gcheck .setglobal
6bfa55
       //pdfdict /.Qqwarning_issued //true .forceput
6bfa55
       .setglobal
6bfa55
       pdfformaterror
6bfa55
     } executeonly ifelse
6bfa55
-  } if
6bfa55
+  } executeonly if
6bfa55
 } bind executeonly odef
6bfa55
 
6bfa55
 % Save PDF gstate
6bfa55
@@ -440,11 +440,12 @@ currentdict /gput_always_allow .undef
6bfa55
   dup type /booleantype eq {
6bfa55
     .currentSMask type /dicttype eq {
6bfa55
       .currentSMask /Processed 2 index .forceput
6bfa55
+    } executeonly
6bfa55
+    {
6bfa55
+      .setSMask
6bfa55
+    }ifelse
6bfa55
   } executeonly
6bfa55
   {
6bfa55
-      .setSMask
6bfa55
-  }ifelse
6bfa55
-  }{
6bfa55
   .setSMask
6bfa55
   }ifelse
6bfa55
 
6bfa55
-- 
6bfa55
2.20.1
6bfa55