summaryrefslogtreecommitdiff
path: root/src/cairo-image-surface.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-02-29 11:49:14 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-03-04 09:31:20 +0000
commitb6eb1c5c92321849661198facd53510366050d45 (patch)
treed59a4f54ca7c47f4e76a87d03bff267d8894072a /src/cairo-image-surface.c
parentc06d929325710c1a2cbecb8a64803ca8e1ffbec0 (diff)
[cairo-image-surface] Harden cairo_format_stride_for_width().
Check the user supplied values for validity and potential overflow, returning -1 in such cases, and update the documentation to warn of the new error return.
Diffstat (limited to 'src/cairo-image-surface.c')
-rw-r--r--src/cairo-image-surface.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 17049979..8247e444 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -418,7 +418,8 @@ _cairo_image_surface_create_with_content (cairo_content_t content,
* </programlisting></informalexample>
*
* Return value: the appropriate stride to use given the desired
- * format and width.
+ * format and width, or -1 if either the format is invalid or the width
+ * too large.
*
* Since: 1.6
**/
@@ -426,7 +427,16 @@ int
cairo_format_stride_for_width (cairo_format_t format,
int width)
{
- int bpp = _cairo_format_bits_per_pixel (format);
+ int bpp;
+
+ if (! CAIRO_FORMAT_VALID (format)) {
+ _cairo_error_throw (CAIRO_STATUS_INVALID_FORMAT);
+ return -1;
+ }
+
+ bpp = _cairo_format_bits_per_pixel (format);
+ if ((unsigned) (width) >= (INT32_MAX - 7) / (unsigned) (bpp))
+ return -1;
return ((bpp*width+7)/8 + STRIDE_ALIGNMENT-1) & ~(STRIDE_ALIGNMENT-1);
}