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

09061c
From: Ken Sharp <ken.sharp@artifex.com>
09061c
Date: Thu, 8 Nov 2018 14:43:32 +0000 (+0000)
09061c
Subject: PS interpreter - check the Implementation of a Pattern before use
09061c
09061c
PS interpreter - check the Implementation of a Pattern before use
09061c
09061c
Bug #700141 "Type confusion in setpattern"
09061c
09061c
As the bug thread says, we were not checking that the Implementation
09061c
of a pattern dictionary was a structure type, leading to a crash when
09061c
we tried to treat it as one.
09061c
09061c
Here we make the st_pattern1_instance and st_pattern2_instance
09061c
structures public definitions and in zsetcolor we check the object
09061c
stored under the Implementation key in the supplied dictionary to see if
09061c
its a t_struct or t_astruct type, and if it is that its a
09061c
st_pattern1_instance or st_pattern2_instance structure.
09061c
09061c
If either check fails we throw a typecheck error.
09061c
09061c
We need to make the st_pattern1_instance and st_pattern2_instance
09061c
definitions public as they are defined in the graphics library and we
09061c
need to check in the interpreter.
09061c
09061c
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=693baf02152119af6e6afd30bb8ec76d14f84bbf
09061c
---
09061c
09061c
diff -up ghostscript-9.07/base/gsptype1.c.cve-2018-19134 ghostscript-9.07/base/gsptype1.c
09061c
--- ghostscript-9.07/base/gsptype1.c.cve-2018-19134	2018-12-06 14:24:51.562580221 +0100
09061c
+++ ghostscript-9.07/base/gsptype1.c	2018-12-06 14:25:19.570310740 +0100
09061c
@@ -50,7 +50,7 @@
09061c
 
09061c
 /* GC descriptors */
09061c
 private_st_pattern1_template();
09061c
-private_st_pattern1_instance();
09061c
+public_st_pattern1_instance();
09061c
 
09061c
 /* GC procedures */
09061c
 static ENUM_PTRS_BEGIN(pattern1_instance_enum_ptrs) {
09061c
diff -up ghostscript-9.07/base/gsptype2.c.cve-2018-19134 ghostscript-9.07/base/gsptype2.c
09061c
--- ghostscript-9.07/base/gsptype2.c.cve-2018-19134	2018-12-06 14:25:51.442004068 +0100
09061c
+++ ghostscript-9.07/base/gsptype2.c	2018-12-06 14:27:26.160092718 +0100
09061c
@@ -33,7 +33,7 @@
09061c
 
09061c
 /* GC descriptors */
09061c
 private_st_pattern2_template();
09061c
-private_st_pattern2_instance();
09061c
+public_st_pattern2_instance();
09061c
 
09061c
 /* GC procedures */
09061c
 static ENUM_PTRS_BEGIN(pattern2_instance_enum_ptrs) {
09061c
@@ -208,7 +208,7 @@ gs_pattern2_set_color(const gs_client_co
09061c
     
09061c
     num_comps = pgs->device->color_info.num_components;
09061c
     for (k = 0; k < num_comps; k++) {
09061c
-        pgs->color_component_map.color_map[k] = 
09061c
+        pgs->color_component_map.color_map[k] =
09061c
             pinst->saved->color_component_map.color_map[k];
09061c
     }
09061c
     code = pcs->type->set_overprint(pcs, pgs);
09061c
diff -up ghostscript-9.07/base/gsptype2.h.cve-2018-19134 ghostscript-9.07/base/gsptype2.h
09061c
--- ghostscript-9.07/base/gsptype2.h.cve-2018-19134	2018-12-06 14:28:16.159611632 +0100
09061c
+++ ghostscript-9.07/base/gsptype2.h	2018-12-06 14:28:53.499252361 +0100
09061c
@@ -57,8 +57,8 @@ typedef struct gs_pattern2_instance_s {
09061c
     bool shfill;
09061c
 } gs_pattern2_instance_t;
09061c
 
09061c
-#define private_st_pattern2_instance() /* in gsptype2.c */\
09061c
-  gs_private_st_composite(st_pattern2_instance, gs_pattern2_instance_t,\
09061c
+#define public_st_pattern2_instance() /* in gsptype2.c */\
09061c
+  gs_public_st_composite(st_pattern2_instance, gs_pattern2_instance_t,\
09061c
     "gs_pattern2_instance_t", pattern2_instance_enum_ptrs,\
09061c
     pattern2_instance_reloc_ptrs)
09061c
 
09061c
diff -up ghostscript-9.07/base/gxcolor2.h.cve-2018-19134 ghostscript-9.07/base/gxcolor2.h
09061c
--- ghostscript-9.07/base/gxcolor2.h.cve-2018-19134	2018-12-06 14:29:16.623029864 +0100
09061c
+++ ghostscript-9.07/base/gxcolor2.h	2018-12-06 14:29:49.115717229 +0100
09061c
@@ -92,8 +92,8 @@ struct gs_pattern1_instance_s {
09061c
     gx_bitmap_id id;		/* key for cached bitmap (= id of mask) */
09061c
 };
09061c
 
09061c
-#define private_st_pattern1_instance() /* in gsptype1.c */\
09061c
-  gs_private_st_composite(st_pattern1_instance, gs_pattern1_instance_t,\
09061c
+#define public_st_pattern1_instance() /* in gsptype1.c */\
09061c
+  gs_public_st_composite(st_pattern1_instance, gs_pattern1_instance_t,\
09061c
     "gs_pattern1_instance_t", pattern1_instance_enum_ptrs,\
09061c
     pattern1_instance_reloc_ptrs)
09061c
 
09061c
diff -up ghostscript-9.07/psi/zcolor.c.cve-2018-19134 ghostscript-9.07/psi/zcolor.c
09061c
--- ghostscript-9.07/psi/zcolor.c.cve-2018-19134	2018-12-06 14:30:27.229350513 +0100
09061c
+++ ghostscript-9.07/psi/zcolor.c	2018-12-06 14:31:52.650528604 +0100
09061c
@@ -57,6 +57,8 @@
09061c
 
09061c
 /* imported from gsht.c */
09061c
 extern  void    gx_set_effective_transfer(gs_state *);
09061c
+extern_st(st_pattern1_instance);
09061c
+extern_st(st_pattern2_instance);
09061c
 
09061c
 /* Essential forward declarations */
09061c
 static int validate_spaces(i_ctx_t *i_ctx_p, ref *arr, int *depth);
09061c
@@ -283,6 +285,9 @@ zsetcolor(i_ctx_t * i_ctx_p)
09061c
             code = array_get(imemory, pImpl, 0, &pPatInst);
09061c
             if (code < 0)
09061c
                 return code;
09061c
+                if (!r_is_struct(&pPatInst) || (!r_has_stype(&pPatInst, imemory, st_pattern1_instance) && !r_has_stype(&pPatInst, imemory, st_pattern2_instance)))
09061c
+                    return_error(gs_error_typecheck);
09061c
+
09061c
             cc.pattern = r_ptr(&pPatInst, gs_pattern_instance_t);
09061c
             n_numeric_comps = ( pattern_instance_uses_base_space(cc.pattern)
09061c
                                   ? n_comps - 1