Blame SOURCES/cairo-1.15.12-CVE-2020-35492.patch

495e36
From 40e9d1a0a69f01b55b4fa131bc253c7c09a0ae91 Mon Sep 17 00:00:00 2001
495e36
From: Heiko Lewin <heiko.lewin@worldiety.de>
495e36
Date: Tue, 15 Dec 2020 16:48:19 +0100
495e36
Subject: [PATCH 1/2] Fix mask usage in image-compositor
495e36
495e36
---
495e36
 src/cairo-image-compositor.c                |   8 ++--
495e36
 test/Makefile.sources                       |   1 +
495e36
 test/bug-image-compositor.c                 |  39 ++++++++++++++++++++
495e36
 test/reference/bug-image-compositor.ref.png | Bin 0 -> 185 bytes
495e36
 4 files changed, 44 insertions(+), 4 deletions(-)
495e36
 create mode 100644 test/bug-image-compositor.c
495e36
 create mode 100644 test/reference/bug-image-compositor.ref.png
495e36
495e36
diff --git a/src/cairo-image-compositor.c b/src/cairo-image-compositor.c
495e36
index 122a8ca42..b20e2ec78 100644
495e36
--- a/src/cairo-image-compositor.c
495e36
+++ b/src/cairo-image-compositor.c
495e36
@@ -2601,14 +2601,14 @@ _inplace_src_spans (void *abstract_renderer, int y, int h,
495e36
 		    unsigned num_spans)
495e36
 {
495e36
     cairo_image_span_renderer_t *r = abstract_renderer;
495e36
-    uint8_t *m;
495e36
+    uint8_t *m, *base = (uint8_t*)pixman_image_get_data(r->mask);
495e36
     int x0;
495e36
 
495e36
     if (num_spans == 0)
495e36
 	return CAIRO_STATUS_SUCCESS;
495e36
 
495e36
     x0 = spans[0].x;
495e36
-    m = r->_buf;
495e36
+    m = base;
495e36
     do {
495e36
 	int len = spans[1].x - spans[0].x;
495e36
 	if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) {
495e36
@@ -2646,7 +2646,7 @@ _inplace_src_spans (void *abstract_renderer, int y, int h,
495e36
 				      spans[0].x, y,
495e36
 				      spans[1].x - spans[0].x, h);
495e36
 
495e36
-	    m = r->_buf;
495e36
+	    m = base;
495e36
 	    x0 = spans[1].x;
495e36
 	} else if (spans[0].coverage == 0x0) {
495e36
 	    if (spans[0].x != x0) {
495e36
@@ -2675,7 +2675,7 @@ _inplace_src_spans (void *abstract_renderer, int y, int h,
495e36
 #endif
495e36
 	    }
495e36
 
495e36
-	    m = r->_buf;
495e36
+	    m = base;
495e36
 	    x0 = spans[1].x;
495e36
 	} else {
495e36
 	    *m++ = spans[0].coverage;
495e36
diff --git a/test/Makefile.sources b/test/Makefile.sources
495e36
index c47131faf..86fd53d15 100644
495e36
--- a/test/Makefile.sources
495e36
+++ b/test/Makefile.sources
495e36
@@ -33,6 +33,7 @@ test_sources = \
495e36
 	bug-source-cu.c					\
495e36
 	bug-extents.c					\
495e36
 	bug-seams.c					\
495e36
+	bug-image-compositor.c				\
495e36
 	caps.c						\
495e36
 	checkerboard.c					\
495e36
 	caps-joins.c					\
495e36
diff --git a/test/bug-image-compositor.c b/test/bug-image-compositor.c
495e36
new file mode 100644
495e36
index 000000000..fc4fd370b
495e36
--- /dev/null
495e36
+++ b/test/bug-image-compositor.c
495e36
@@ -0,0 +1,39 @@
495e36
+#include "cairo-test.h"
495e36
+
495e36
+static cairo_test_status_t
495e36
+draw (cairo_t *cr, int width, int height)
495e36
+{
495e36
+    cairo_set_source_rgb (cr, 0., 0., 0.);
495e36
+    cairo_paint (cr);
495e36
+
495e36
+    cairo_set_source_rgb (cr, 1., 1., 1.);
495e36
+    cairo_set_line_width (cr, 1.);
495e36
+
495e36
+    cairo_pattern_t *p = cairo_pattern_create_linear (0, 0, width, height);
495e36
+    cairo_pattern_add_color_stop_rgb (p, 0, 0.99, 1, 1);
495e36
+    cairo_pattern_add_color_stop_rgb (p, 1, 1, 1, 1);
495e36
+    cairo_set_source (cr, p);
495e36
+
495e36
+    cairo_move_to (cr, 0.5, -1);
495e36
+    for (int i = 0; i < width; i+=3) {
495e36
+	cairo_rel_line_to (cr, 2, 2);
495e36
+	cairo_rel_line_to (cr, 1, -2);
495e36
+    }
495e36
+
495e36
+    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
495e36
+    cairo_stroke (cr);
495e36
+
495e36
+    cairo_pattern_destroy(p);
495e36
+
495e36
+    return CAIRO_TEST_SUCCESS;
495e36
+}
495e36
+
495e36
+
495e36
+CAIRO_TEST (bug_image_compositor,
495e36
+	    "Crash in image-compositor",
495e36
+	    "stroke, stress", /* keywords */
495e36
+	    NULL, /* requirements */
495e36
+	    10000, 1,
495e36
+	    NULL, draw)
495e36
+	    
495e36
+	    
495e36
diff --git a/test/reference/bug-image-compositor.ref.png b/test/reference/bug-image-compositor.ref.png
495e36
new file mode 100644
495e36
index 0000000000000000000000000000000000000000..939f659d2c8620e9927a3a79f5e96fb639c418be
495e36
GIT binary patch
495e36
literal 185
495e36
zcmeAS@N?(olHy`uVBq!ia0y~yP!|BQ89A7M<o7+wF+hqf$=lt9;Xep2*t>i(P$bXO
495e36
z#WAE}&f8-f1se=_SPWL_NSx=C)BnJ0eBr6Z%1egFEOv(*t#+|{>X&v^RS7GQe(vez
495e36
lf)$wgmAfM(p2Sx&&i!{gWy)N&qd=P(JYD@<);T3K0RWsgHuC@g
495e36
495e36
literal 0
495e36
HcmV?d00001
495e36
495e36
-- 
495e36
2.34.1
495e36
495e36
495e36
From afc23bfdc3c2597b9fe0ee34b9b4bfa47fa03698 Mon Sep 17 00:00:00 2001
495e36
From: Heiko Lewin <heiko.lewin@worldiety.de>
495e36
Date: Tue, 15 Dec 2020 17:14:18 +0100
495e36
Subject: [PATCH 2/2] Minor cleanups
495e36
495e36
---
495e36
 test/bug-image-compositor.c | 33 ++++++++++++++++++++++++++++++---
495e36
 1 file changed, 30 insertions(+), 3 deletions(-)
495e36
495e36
diff --git a/test/bug-image-compositor.c b/test/bug-image-compositor.c
495e36
index fc4fd370b..304ea089c 100644
495e36
--- a/test/bug-image-compositor.c
495e36
+++ b/test/bug-image-compositor.c
495e36
@@ -1,5 +1,34 @@
495e36
+/*
495e36
+ * Copyright © 2020 Uli Schlachter, Heiko Lewin
495e36
+ *
495e36
+ * Permission is hereby granted, free of charge, to any person
495e36
+ * obtaining a copy of this software and associated documentation
495e36
+ * files (the "Software"), to deal in the Software without
495e36
+ * restriction, including without limitation the rights to use, copy,
495e36
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
495e36
+ * of the Software, and to permit persons to whom the Software is
495e36
+ * furnished to do so, subject to the following conditions:
495e36
+ *
495e36
+ * The above copyright notice and this permission notice shall be
495e36
+ * included in all copies or substantial portions of the Software.
495e36
+ *
495e36
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
495e36
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
495e36
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
495e36
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
495e36
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
495e36
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
495e36
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
495e36
+ * SOFTWARE.
495e36
+ *
495e36
+ * Author: Uli Schlachter <psychon@znc.in>
495e36
+ * Author: Heiko Lewin <hlewin@gmx.de>
495e36
+ */
495e36
 #include "cairo-test.h"
495e36
 
495e36
+
495e36
+/* This test reproduces an overflow of a mask-buffer in cairo-image-compositor.c */
495e36
+
495e36
 static cairo_test_status_t
495e36
 draw (cairo_t *cr, int width, int height)
495e36
 {
495e36
@@ -13,6 +42,7 @@ draw (cairo_t *cr, int width, int height)
495e36
     cairo_pattern_add_color_stop_rgb (p, 0, 0.99, 1, 1);
495e36
     cairo_pattern_add_color_stop_rgb (p, 1, 1, 1, 1);
495e36
     cairo_set_source (cr, p);
495e36
+    cairo_pattern_destroy(p);
495e36
 
495e36
     cairo_move_to (cr, 0.5, -1);
495e36
     for (int i = 0; i < width; i+=3) {
495e36
@@ -23,8 +53,6 @@ draw (cairo_t *cr, int width, int height)
495e36
     cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
495e36
     cairo_stroke (cr);
495e36
 
495e36
-    cairo_pattern_destroy(p);
495e36
-
495e36
     return CAIRO_TEST_SUCCESS;
495e36
 }
495e36
 
495e36
@@ -36,4 +64,3 @@ CAIRO_TEST (bug_image_compositor,
495e36
 	    10000, 1,
495e36
 	    NULL, draw)
495e36
 	    
495e36
-	    
495e36
-- 
495e36
2.34.1
495e36