Merge commit from fork

Follow-up to #6090 (GHSA-h2xh-wmpf-pwp5).  #6090 saturated the
float->int conversions in emit_segment() via hb_clamp_to<int32_t>, but a
saturated edge endpoint (INT32_MAX) then overflows the ceil-round in the
auto-size path of hb_raster_draw_render():

  int x1 = (xmax + HB_RASTER_PIXEL_MASK) >> HB_RASTER_PIXEL_BITS;

With xmax == INT32_MAX this is INT32_MAX + 255, signed overflow (UB).
UBSan fires on the accepted PoC (single spec-legal PaintTransform,
scale 32767.99) at the first painted glyph.  Widen the +MASK step to
int64_t before the shift.

Also saturate the four float->int corner conversions in
hb_raster_paint_push_clip_rectangle() through hb_clamp_to<int32_t>, the
same unguarded pattern #6090 clamped elsewhere in this file (reachable
via PaintColrGlyph under a large PaintTransform); the subtraction is done
in double to avoid overflow, and NaN maps to INT32_MIN.

Verified with -fsanitize=address,undefined: the PoC (NEST=1 and NEST=9)
and full-font render of the base font produce zero runtime errors;
without the draw.cc change the PoC reports the signed-overflow above.
This commit is contained in:
punishell authored and GitHub committed 2026-07-31 01:08:01 -06:00
1 parent 86e7473f0d
commit 51e229759f
2 files changed
+13 -7

No files matched your search

+5 -3
View File
@@ -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;
+8 -4
View File
@@ -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<int32_t> ((double) floorf (fmin_x) - surf->extents.x_origin);
int py0 = hb_clamp_to<int32_t> ((double) floorf (fmin_y) - surf->extents.y_origin);
int px1 = hb_clamp_to<int32_t> ((double) ceilf (fmax_x) - surf->extents.x_origin);
int py1 = hb_clamp_to<int32_t> ((double) ceilf (fmax_y) - surf->extents.y_origin);
/* Clamp to surface bounds */
px0 = hb_max (px0, 0);