1 From 03a820b173ed1fdef6ff14b4468f5dbc02ff59be Mon Sep 17 00:00:00 2001
2 From: Heiko Lewin <heiko.lewin@worldiety.de>
3 Date: Tue, 15 Dec 2020 16:48:19 +0100
4 Subject: [PATCH 1/3] Fix mask usage in image-compositor
7 src/cairo-image-compositor.c | 8 ++--
8 test/Makefile.sources | 1 +
9 test/bug-image-compositor.c | 39 ++++++++++++++++++++
10 test/reference/bug-image-compositor.ref.png | Bin 0 -> 185 bytes
11 4 files changed, 44 insertions(+), 4 deletions(-)
12 create mode 100644 test/bug-image-compositor.c
13 create mode 100644 test/reference/bug-image-compositor.ref.png
15 --- a/src/cairo-image-compositor.c
16 +++ b/src/cairo-image-compositor.c
17 @@ -2601,14 +2601,14 @@ _inplace_src_spans (void *abstract_rende
20 cairo_image_span_renderer_t *r = abstract_renderer;
22 + uint8_t *m, *base = (uint8_t*)pixman_image_get_data(r->mask);
26 return CAIRO_STATUS_SUCCESS;
32 int len = spans[1].x - spans[0].x;
33 if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) {
34 @@ -2646,7 +2646,7 @@ _inplace_src_spans (void *abstract_rende
36 spans[1].x - spans[0].x, h);
41 } else if (spans[0].coverage == 0x0) {
42 if (spans[0].x != x0) {
43 @@ -2675,7 +2675,7 @@ _inplace_src_spans (void *abstract_rende
51 *m++ = spans[0].coverage;
53 +++ b/test/bug-image-compositor.c
56 + * Copyright © 2020 Uli Schlachter, Heiko Lewin
58 + * Permission is hereby granted, free of charge, to any person
59 + * obtaining a copy of this software and associated documentation
60 + * files (the "Software"), to deal in the Software without
61 + * restriction, including without limitation the rights to use, copy,
62 + * modify, merge, publish, distribute, sublicense, and/or sell copies
63 + * of the Software, and to permit persons to whom the Software is
64 + * furnished to do so, subject to the following conditions:
66 + * The above copyright notice and this permission notice shall be
67 + * included in all copies or substantial portions of the Software.
69 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
70 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
72 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
73 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
74 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
75 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
78 + * Author: Uli Schlachter <psychon@znc.in>
79 + * Author: Heiko Lewin <hlewin@gmx.de>
81 +#include "cairo-test.h"
84 +/* This test reproduces an overflow of a mask-buffer in cairo-image-compositor.c */
86 +static cairo_test_status_t
87 +draw (cairo_t *cr, int width, int height)
89 + cairo_set_source_rgb (cr, 0., 0., 0.);
92 + cairo_set_source_rgb (cr, 1., 1., 1.);
93 + cairo_set_line_width (cr, 1.);
95 + cairo_pattern_t *p = cairo_pattern_create_linear (0, 0, width, height);
96 + cairo_pattern_add_color_stop_rgb (p, 0, 0.99, 1, 1);
97 + cairo_pattern_add_color_stop_rgb (p, 1, 1, 1, 1);
98 + cairo_set_source (cr, p);
99 + cairo_pattern_destroy(p);
101 + cairo_move_to (cr, 0.5, -1);
102 + for (int i = 0; i < width; i+=3) {
103 + cairo_rel_line_to (cr, 2, 2);
104 + cairo_rel_line_to (cr, 1, -2);
107 + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
110 + return CAIRO_TEST_SUCCESS;
114 +CAIRO_TEST (bug_image_compositor,
115 + "Crash in image-compositor",
116 + "stroke, stress", /* keywords */
117 + NULL, /* requirements */