[cairo-commit] 2 commits - src/cairo-image-surface.c

Chris Wilson ickle at kemper.freedesktop.org
Tue Oct 28 04:06:32 PDT 2008


 src/cairo-image-surface.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

New commits:
commit 1327ec232cfca675647fb03876487c92fb638354
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Oct 28 10:00:38 2008 +0000

    [image] Remove invalid assert.
    
    The assert can fail for an error surface.
    
    TODO: Decide what values should be returned from getters for error
    surfaces.

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 3de0568..4aad77f 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -572,8 +572,6 @@ cairo_image_surface_get_format (cairo_surface_t *surface)
 	return 0;
     }
 
-    assert (CAIRO_FORMAT_VALID (image_surface->format));
-
     return image_surface->format;
 }
 
commit 9481d999df8d399543bdbb45b85bd24b1725bece
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Oct 28 09:59:01 2008 +0000

    [image] Check create_for_data() to ensure a valid minimum stride.
    
    Double check that the user is not being silly by passing in a stride that
    is too small for the width. evince/poppler is one such example...

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 95363c4..3de0568 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -484,6 +484,7 @@ cairo_image_surface_create_for_data (unsigned char     *data,
 				     int		stride)
 {
     pixman_format_code_t pixman_format;
+    int minstride;
 
     if (! CAIRO_FORMAT_VALID (format))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
@@ -491,6 +492,17 @@ cairo_image_surface_create_for_data (unsigned char     *data,
     if ((stride & (CAIRO_STRIDE_ALIGNMENT-1)) != 0)
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
 
+    minstride = cairo_format_stride_for_width (format, width);
+    if (stride < 0) {
+	if (stride > -minstride) {
+	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
+	}
+    } else {
+	if (stride < minstride) {
+	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
+	}
+    }
+
     pixman_format = _cairo_format_to_pixman_format_code (format);
 
     return _cairo_image_surface_create_with_pixman_format (data, pixman_format,


More information about the cairo-commit mailing list