[cairo] [PATCH] Avoid potential crash when subsurface's size is less than 0.
Bill Spitzak
spitzak at gmail.com
Tue Mar 13 10:00:52 PDT 2012
On 03/12/2012 07:00 PM, Chuanbo Weng wrote:
> 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 */
Why not use:
extents.x = floor(x);
extents.width = ceil(width);
This will produce a positive size as long as width is positive.
More information about the cairo
mailing list