Benjamin Otte 8d13f1
From 00de16b7ac54d4c620e0be3565c83f58e01567ac Mon Sep 17 00:00:00 2001
Benjamin Otte 8d13f1
From: Benjamin Otte <otte@redhat.com>
Benjamin Otte 8d13f1
Date: Sat, 4 Jun 2011 13:47:15 +0200
Benjamin Otte 8d13f1
Subject: [PATCH] image: Don't crash on weird pixman formats
Benjamin Otte 8d13f1
Benjamin Otte 8d13f1
_pixel_to_solid() used to assert that it got a known cairo_format_t.
Benjamin Otte 8d13f1
However, this might not be the case when backends decide to use a pixman
Benjamin Otte 8d13f1
format that is not representable by a cairo format (X and DirectFB are
Benjamin Otte 8d13f1
examples for backends that do that).
Benjamin Otte 8d13f1
Benjamin Otte 8d13f1
This patch makes _pixel_to_solid() return NULL in that case and fixes
Benjamin Otte 8d13f1
the callers to deal with it.
Benjamin Otte 8d13f1
Benjamin Otte 8d13f1
https://bugs.freedesktop.org/show_bug.cgi?id=37916
Benjamin Otte 8d13f1
---
Benjamin Otte 8d13f1
 src/cairo-image-surface.c |   23 ++++++++++++++++-------
Benjamin Otte 8d13f1
 1 files changed, 16 insertions(+), 7 deletions(-)
Benjamin Otte 8d13f1
Benjamin Otte 8d13f1
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
Benjamin Otte 8d13f1
index 93ccfe5..a2345b2 100644
Benjamin Otte 8d13f1
--- a/src/cairo-image-surface.c
Benjamin Otte 8d13f1
+++ b/src/cairo-image-surface.c
Benjamin Otte 8d13f1
@@ -1246,10 +1246,12 @@ _pixel_to_solid (cairo_image_surface_t *image, int x, int y)
Benjamin Otte 8d13f1
 
Benjamin Otte 8d13f1
     switch (image->format) {
Benjamin Otte 8d13f1
     default:
Benjamin Otte 8d13f1
-    case CAIRO_FORMAT_INVALID:
Benjamin Otte 8d13f1
 	ASSERT_NOT_REACHED;
Benjamin Otte 8d13f1
 	return NULL;
Benjamin Otte 8d13f1
 
Benjamin Otte 8d13f1
+    case CAIRO_FORMAT_INVALID:
Benjamin Otte 8d13f1
+	return NULL;
Benjamin Otte 8d13f1
+
Benjamin Otte 8d13f1
     case CAIRO_FORMAT_A1:
Benjamin Otte 8d13f1
 	pixel = *(uint8_t *) (image->data + y * image->stride + x/8);
Benjamin Otte 8d13f1
 	return pixel & (1 << (x&7)) ? _pixman_black_image () : _pixman_transparent_image ();
Benjamin Otte 8d13f1
@@ -1364,7 +1366,9 @@ _pixman_image_for_surface (const cairo_surface_pattern_t *pattern,
Benjamin Otte 8d13f1
 		}
Benjamin Otte 8d13f1
 		else
Benjamin Otte 8d13f1
 		{
Benjamin Otte 8d13f1
-		    return _pixel_to_solid (source, sample.x, sample.y);
Benjamin Otte 8d13f1
+		    pixman_image = _pixel_to_solid (source, sample.x, sample.y);
Benjamin Otte 8d13f1
+                    if (pixman_image)
Benjamin Otte 8d13f1
+                        return pixman_image;
Benjamin Otte 8d13f1
 		}
Benjamin Otte 8d13f1
 	    }
Benjamin Otte 8d13f1
 
Benjamin Otte 8d13f1
@@ -1403,9 +1407,11 @@ _pixman_image_for_surface (const cairo_surface_pattern_t *pattern,
Benjamin Otte 8d13f1
 
Benjamin Otte 8d13f1
 	    if (sample.width == 1 && sample.height == 1) {
Benjamin Otte 8d13f1
 		if (is_contained) {
Benjamin Otte 8d13f1
-		    return _pixel_to_solid (source,
Benjamin Otte 8d13f1
-					    sub->extents.x + sample.x,
Benjamin Otte 8d13f1
-					    sub->extents.y + sample.y);
Benjamin Otte 8d13f1
+		    pixman_image = _pixel_to_solid (source,
Benjamin Otte 8d13f1
+                                                    sub->extents.x + sample.x,
Benjamin Otte 8d13f1
+                                                    sub->extents.y + sample.y);
Benjamin Otte 8d13f1
+                    if (pixman_image)
Benjamin Otte 8d13f1
+                        return pixman_image;
Benjamin Otte 8d13f1
 		} else {
Benjamin Otte 8d13f1
 		    if (extend == CAIRO_EXTEND_NONE)
Benjamin Otte 8d13f1
 			return _pixman_transparent_image ();
Benjamin Otte 8d13f1
@@ -1468,8 +1474,11 @@ _pixman_image_for_surface (const cairo_surface_pattern_t *pattern,
Benjamin Otte 8d13f1
 	    else
Benjamin Otte 8d13f1
 	    {
Benjamin Otte 8d13f1
 		pixman_image = _pixel_to_solid (image, sample.x, sample.y);
Benjamin Otte 8d13f1
-		_cairo_surface_release_source_image (pattern->surface, image, extra);
Benjamin Otte 8d13f1
-		return pixman_image;
Benjamin Otte 8d13f1
+                if (pixman_image)
Benjamin Otte 8d13f1
+                {
Benjamin Otte 8d13f1
+                    _cairo_surface_release_source_image (pattern->surface, image, extra);
Benjamin Otte 8d13f1
+                    return pixman_image;
Benjamin Otte 8d13f1
+                }
Benjamin Otte 8d13f1
 	    }
Benjamin Otte 8d13f1
 	}
Benjamin Otte 8d13f1
 
Benjamin Otte 8d13f1
-- 
Benjamin Otte 8d13f1
1.7.7.6
Benjamin Otte 8d13f1