mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2025-12-27 04:40:11 +01:00
subsurface: Avoid potential crash when subsurface's size is less than 0
When cairo_surface_create_for_rectangle() is given non-integer parameters, the subsurface's size may be negative(e.g x = 0.2, width = 0.7, the final width will be -1). This illegal surface may cause crash somewhere upon later use, and although the fractional subsurface is ill-defined, we should never crash!
This commit is contained in:
parent
d67f02e23e
commit
91113a9e45
1 changed files with 5 additions and 0 deletions
|
|
@ -461,6 +461,9 @@ cairo_surface_create_for_rectangle (cairo_surface_t *target,
|
|||
{
|
||||
cairo_surface_subsurface_t *surface;
|
||||
|
||||
if (unlikely (width < 0 || height < 0))
|
||||
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
|
||||
|
||||
if (unlikely (target->status))
|
||||
return _cairo_surface_create_in_error (target->status);
|
||||
if (unlikely (target->finished))
|
||||
|
|
@ -484,6 +487,8 @@ cairo_surface_create_for_rectangle (cairo_surface_t *target,
|
|||
surface->extents.y = ceil (y);
|
||||
surface->extents.width = floor (x + width) - surface->extents.x;
|
||||
surface->extents.height = floor (y + height) - surface->extents.y;
|
||||
if ((surface->extents.width | surface->extents.height) < 0)
|
||||
surface->extents.width = surface->extents.height = 0;
|
||||
|
||||
if (target->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) {
|
||||
/* Maintain subsurfaces as 1-depth */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue