pixman: Branch 'master' - 3 commits
Søren Sandmann Pedersen
sandmann at kemper.freedesktop.org
Tue Dec 18 09:57:57 PST 2012
pixman/pixman-edge.c | 1
pixman/pixman-trap.c | 7 +-
test/stress-test.c | 160 +++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 141 insertions(+), 27 deletions(-)
New commits:
commit 6a6c8c51ed9e7272e624b3c99187ddf71d19a0fd
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date: Thu Dec 13 15:37:40 2012 -0500
pixman_composite_trapezoids(): Check for NULL return from create_bits()
A check is needed that the creation of the temporary image in
pixman_composite_trapezoids() succeeds.
Fixes crash in stress-test -s 0x313c on my system.
diff --git a/pixman/pixman-trap.c b/pixman/pixman-trap.c
index 4dad179..91766fd 100644
--- a/pixman/pixman-trap.c
+++ b/pixman/pixman-trap.c
@@ -523,8 +523,9 @@ pixman_composite_trapezoids (pixman_op_t op,
if (!get_trap_extents (op, dst, traps, n_traps, &box))
return;
- tmp = pixman_image_create_bits (
- mask_format, box.x2 - box.x1, box.y2 - box.y1, NULL, -1);
+ if (!(tmp = pixman_image_create_bits (
+ mask_format, box.x2 - box.x1, box.y2 - box.y1, NULL, -1)))
+ return;
for (i = 0; i < n_traps; ++i)
{
commit c2cb303d33ec11390b93cabd90f0f95bc9264113
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date: Thu Dec 13 15:26:17 2012 -0500
pixman_composite_trapezoids: Return early if mask_format is not of TYPE_ALPHA
stress-test -s 0x17ee crashes because pixman_composite_trapezoids() is
given a mask_format of PIXMAN_c8, which causes it to create a
temporary image with that format but without a palette. This causes
crashes later.
The only mask_format that we actually support are those of TYPE_ALPHA,
so this patch add a return_if_fail() to ensure this.
Similarly, although currently it won't crash if given an invalid
format, alpha-only formats have always been the only thing that made
sense for the pixman_rasterize_edges() functions, so add a
return_if_fail() ensuring that the destination format is of type
PIXMAN_TYPE_ALPHA.
diff --git a/pixman/pixman-edge.c b/pixman/pixman-edge.c
index 8d498ab..ad6dfc4 100644
--- a/pixman/pixman-edge.c
+++ b/pixman/pixman-edge.c
@@ -374,6 +374,7 @@ pixman_rasterize_edges (pixman_image_t *image,
pixman_fixed_t b)
{
return_if_fail (image->type == BITS);
+ return_if_fail (PIXMAN_FORMAT_TYPE (image->bits.format) == PIXMAN_TYPE_A);
if (image->bits.read_func || image->bits.write_func)
pixman_rasterize_edges_accessors (image, l, r, t, b);
diff --git a/pixman/pixman-trap.c b/pixman/pixman-trap.c
index ab5c8c8..4dad179 100644
--- a/pixman/pixman-trap.c
+++ b/pixman/pixman-trap.c
@@ -491,6 +491,8 @@ pixman_composite_trapezoids (pixman_op_t op,
{
int i;
+ return_if_fail (PIXMAN_FORMAT_TYPE (mask_format) == PIXMAN_TYPE_A);
+
if (n_traps <= 0)
return;
commit 1f0c02811ea71b36380b9d4029a248659bd9af50
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date: Thu Dec 13 11:21:16 2012 -0500
Add testing of trapezoids to stress-test
The entry points add_trapezoids(), rasterize_trapezoid() and
composite_trapezoid() are exercised with random trapezoids.
This uncovers crashes with stress-test seeds 0x17ee and 0x313c.
diff --git a/test/stress-test.c b/test/stress-test.c
index ee55c21..9d949af 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -205,8 +205,29 @@ rand_y (pixman_image_t *image)
return log_rand ();
}
+static pixman_format_code_t
+random_format (pixman_bool_t prefer_alpha)
+{
+ pixman_format_code_t format;
+ int n = prng_rand_n (ARRAY_LENGTH (image_formats));
+
+ if (prefer_alpha && prng_rand_n (4) != 0)
+ {
+ do
+ {
+ format = image_formats[n++ % ARRAY_LENGTH (image_formats)];
+ } while (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_A);
+ }
+ else
+ {
+ format = image_formats[n];
+ }
+
+ return format;
+}
+
static pixman_image_t *
-create_random_bits_image (void)
+create_random_bits_image (pixman_bool_t prefer_alpha)
{
pixman_format_code_t format;
pixman_indexed_t *indexed;
@@ -220,7 +241,7 @@ create_random_bits_image (void)
int n_coefficients = 0;
/* format */
- format = image_formats[prng_rand_n (ARRAY_LENGTH (image_formats))];
+ format = random_format (prefer_alpha);
indexed = NULL;
if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_COLOR)
@@ -389,7 +410,7 @@ set_general_properties (pixman_image_t *image, pixman_bool_t allow_alpha_map)
pixman_image_t *alpha_map;
int16_t x, y;
- alpha_map = create_random_bits_image ();
+ alpha_map = create_random_bits_image (FALSE);
if (alpha_map)
{
@@ -695,7 +716,7 @@ create_random_image (void)
{
default:
case 0:
- result = create_random_bits_image ();
+ result = create_random_bits_image (FALSE);
break;
case 1:
@@ -721,6 +742,39 @@ create_random_image (void)
return result;
}
+static void
+random_line (pixman_line_fixed_t *line, int width, int height)
+{
+ line->p1.x = prng_rand_n (width) << 16;
+ line->p1.y = prng_rand_n (height) << 16;
+ line->p2.x = prng_rand_n (width) << 16;
+ line->p2.y = prng_rand_n (height) << 16;
+}
+
+static pixman_trapezoid_t *
+create_random_trapezoids (int *n_traps, int height, int width)
+{
+ pixman_trapezoid_t *trapezoids;
+ int i;
+
+ *n_traps = prng_rand_n (16) + 1;
+
+ trapezoids = malloc (sizeof (pixman_trapezoid_t) * *n_traps);
+
+ for (i = 0; i < *n_traps; ++i)
+ {
+ pixman_trapezoid_t *t = &(trapezoids[i]);
+
+ t->top = prng_rand_n (height) << 16;
+ t->bottom = prng_rand_n (height) << 16;
+
+ random_line (&t->left, height, width);
+ random_line (&t->right, height, width);
+ }
+
+ return trapezoids;
+}
+
static const pixman_op_t op_list[] =
{
PIXMAN_OP_SRC,
@@ -792,31 +846,87 @@ run_test (uint32_t seed, pixman_bool_t verbose, uint32_t mod)
if (mod == 0 || (seed % mod) == 0)
printf ("Seed 0x%08x\n", seed);
}
-
- prng_srand (seed);
- source = create_random_image ();
- mask = create_random_image ();
- dest = create_random_bits_image ();
+ source = mask = dest = NULL;
+
+ prng_srand (seed);
- if (source && mask && dest)
+ if (prng_rand_n (8) == 0)
{
- set_general_properties (dest, TRUE);
-
- op = op_list [prng_rand_n (ARRAY_LENGTH (op_list))];
-
- pixman_image_composite32 (op,
- source, mask, dest,
- rand_x (source), rand_y (source),
- rand_x (mask), rand_y (mask),
- 0, 0,
- dest->bits.width,
- dest->bits.height);
+ int n_traps;
+ pixman_trapezoid_t *trapezoids;
+
+ dest = create_random_bits_image (TRUE);
+
+ if (dest)
+ {
+ set_general_properties (dest, TRUE);
+
+ trapezoids = create_random_trapezoids (
+ &n_traps, dest->bits.width, dest->bits.height);
+
+ if (trapezoids)
+ {
+ switch (prng_rand_n (3))
+ {
+ case 0:
+ pixman_rasterize_trapezoid (
+ dest, &trapezoids[prng_rand_n (n_traps)],
+ rand_x (dest), rand_y (dest));
+ break;
+
+ case 1:
+ source = create_random_image ();
+
+ if (source)
+ {
+ op = op_list [prng_rand_n (ARRAY_LENGTH (op_list))];
+
+ pixman_composite_trapezoids (
+ op, source, dest,
+ random_format (TRUE),
+ rand_x (source), rand_y (source),
+ rand_x (dest), rand_y (dest),
+ n_traps, trapezoids);
+ }
+ break;
+
+ case 2:
+ pixman_add_trapezoids (
+ dest, rand_x (dest), rand_y (dest), n_traps, trapezoids);
+ break;
+ }
+
+ free (trapezoids);
+ }
+ }
}
- if (source)
- pixman_image_unref (source);
- if (mask)
- pixman_image_unref (mask);
+ else
+ {
+ dest = create_random_bits_image (FALSE);
+ source = create_random_image ();
+ mask = create_random_image ();
+
+ if (source && mask && dest)
+ {
+ set_general_properties (dest, TRUE);
+
+ op = op_list [prng_rand_n (ARRAY_LENGTH (op_list))];
+
+ pixman_image_composite32 (op,
+ source, mask, dest,
+ rand_x (source), rand_y (source),
+ rand_x (mask), rand_y (mask),
+ 0, 0,
+ dest->bits.width,
+ dest->bits.height);
+ }
+ }
+
+ if (source)
+ pixman_image_unref (source);
+ if (mask)
+ pixman_image_unref (mask);
if (dest)
pixman_image_unref (dest);
}
More information about the xorg-commit
mailing list