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

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