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

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