[cairo] [PATCH] Avoid potential crash when subsurface's size is less than 0.

Chuanbo Weng strgnm at gmail.com
Mon Mar 12 19:00:37 PDT 2012


When cairo_surface_create_for_rectangle() get non-integer parameters,
the subsurface's size may be negative(e.g x = 0.2, width = 0.7, the
final width will be -1). It may cause crash somewhere when use this
subsurface. Although fractional surface is ill-defined, we should avoid
crash when pass non-integer parameter.
---
 src/cairo-surface-subsurface.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/cairo-surface-subsurface.c b/src/cairo-surface-subsurface.c
index 8590bf0..a9fae4b 100644
--- a/src/cairo-surface-subsurface.c
+++ b/src/cairo-surface-subsurface.c
@@ -483,7 +483,9 @@ cairo_surface_create_for_rectangle (cairo_surface_t *target,
     surface->extents.x = ceil (x);
     surface->extents.y = ceil (y);
     surface->extents.width = floor (x + width) - surface->extents.x;
+    surface->extents.width = surface->extents.width >= 0 ? surface->extents.width : 0;
     surface->extents.height = floor (y + height) - surface->extents.y;
+    surface->extents.height = surface->extents.height >= 0 ? surface->extents.height : 0;
 
     if (target->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) {
 	/* Maintain subsurfaces as 1-depth */
-- 
1.7.5.4



More information about the cairo mailing list