diff --git a/src/hb-raster-draw.cc b/src/hb-raster-draw.cc index 3b77fea1b..ece9e068d 100644 --- a/src/hb-raster-draw.cc +++ b/src/hb-raster-draw.cc @@ -1289,11 +1289,13 @@ hb_raster_draw_render (hb_raster_draw_t *draw) ymax = hb_max (ymax, e.yH); } - /* Convert fixed-point → pixels (floor for min, ceil for max) */ + /* Convert fixed-point → pixels (floor for min, ceil for max). Edge + coordinates are saturated to int32 range in emit_segment, so the + +MASK ceil step must be widened to avoid signed overflow. */ int x0 = xmin >> HB_RASTER_PIXEL_BITS; int y0 = ymin >> HB_RASTER_PIXEL_BITS; - int x1 = (xmax + HB_RASTER_PIXEL_MASK) >> HB_RASTER_PIXEL_BITS; - int y1 = (ymax + HB_RASTER_PIXEL_MASK) >> HB_RASTER_PIXEL_BITS; + int x1 = (int) (((int64_t) xmax + HB_RASTER_PIXEL_MASK) >> HB_RASTER_PIXEL_BITS); + int y1 = (int) (((int64_t) ymax + HB_RASTER_PIXEL_MASK) >> HB_RASTER_PIXEL_BITS); ext.x_origin = x0; ext.y_origin = y0; diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index 779c3d99c..edee5fd3a 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -433,10 +433,14 @@ hb_raster_paint_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED, fmax_x = hb_max (fmax_x, cx[i]); fmax_y = hb_max (fmax_y, cy[i]); } - int px0 = (int) floorf (fmin_x) - surf->extents.x_origin; - int py0 = (int) floorf (fmin_y) - surf->extents.y_origin; - int px1 = (int) ceilf (fmax_x) - surf->extents.x_origin; - int py1 = (int) ceilf (fmax_y) - surf->extents.y_origin; + /* A spec-legal but very large transform can push these bounds past the int + range or to non-finite values; a bare float->int conversion would then be + undefined. Saturate through hb_clamp_to<> (which also maps NaN to + INT32_MIN); the subtraction is done in double to avoid overflow. */ + int px0 = hb_clamp_to ((double) floorf (fmin_x) - surf->extents.x_origin); + int py0 = hb_clamp_to ((double) floorf (fmin_y) - surf->extents.y_origin); + int px1 = hb_clamp_to ((double) ceilf (fmax_x) - surf->extents.x_origin); + int py1 = hb_clamp_to ((double) ceilf (fmax_y) - surf->extents.y_origin); /* Clamp to surface bounds */ px0 = hb_max (px0, 0);