From 0855a58fdf7dcfc690822c8c329a9c57565c8c2d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Aug 2026 18:17:37 -0600 Subject: [PATCH] [bitmap] Clamp scaled glyph extents Bitmap strike scaling converts attacker-controlled image dimensions and offsets to glyph positions through unchecked float and mixed-sign arithmetic. Widen the sbix coordinate sum and clamp scaled sbix and CBDT extents. This is part of the complete position-overflow fix for issue #6151. Testing: meson test -C build --print-errorlogs Assisted-by: Codex --- src/OT/Color/CBDT/CBDT.hh | 8 ++++---- src/OT/Color/sbix/sbix.hh | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/OT/Color/CBDT/CBDT.hh b/src/OT/Color/CBDT/CBDT.hh index 0bfaf8c46..f11dab7bc 100644 --- a/src/OT/Color/CBDT/CBDT.hh +++ b/src/OT/Color/CBDT/CBDT.hh @@ -885,10 +885,10 @@ struct CBDT { float x_scale = upem / (float) strike.ppemX; float y_scale = upem / (float) strike.ppemY; - extents->x_bearing = roundf (extents->x_bearing * x_scale); - extents->y_bearing = roundf (extents->y_bearing * y_scale); - extents->width = roundf (extents->width * x_scale); - extents->height = roundf (extents->height * y_scale); + extents->x_bearing = hb_clamp_to (roundf (extents->x_bearing * x_scale)); + extents->y_bearing = hb_clamp_to (roundf (extents->y_bearing * y_scale)); + extents->width = hb_clamp_to (roundf (extents->width * x_scale)); + extents->height = hb_clamp_to (roundf (extents->height * y_scale)); } return true; diff --git a/src/OT/Color/sbix/sbix.hh b/src/OT/Color/sbix/sbix.hh index b5760053a..9060df713 100644 --- a/src/OT/Color/sbix/sbix.hh +++ b/src/OT/Color/sbix/sbix.hh @@ -337,18 +337,18 @@ struct sbix } extents->x_bearing = x_offset; - extents->y_bearing = png.IHDR.height + y_offset; - extents->width = png.IHDR.width; - extents->height = -1 * png.IHDR.height; + extents->y_bearing = hb_clamp_to ((int64_t) (unsigned int) png.IHDR.height + y_offset); + extents->width = (hb_position_t) (unsigned int) png.IHDR.width; + extents->height = -(hb_position_t) (unsigned int) png.IHDR.height; /* Convert to font units. */ if (strike_ppem && scale) { float scale = font->face->get_upem () / (float) strike_ppem; - extents->x_bearing = roundf (extents->x_bearing * scale); - extents->y_bearing = roundf (extents->y_bearing * scale); - extents->width = roundf (extents->width * scale); - extents->height = roundf (extents->height * scale); + extents->x_bearing = hb_clamp_to (roundf (extents->x_bearing * scale)); + extents->y_bearing = hb_clamp_to (roundf (extents->y_bearing * scale)); + extents->width = hb_clamp_to (roundf (extents->width * scale)); + extents->height = hb_clamp_to (roundf (extents->height * scale)); } if (scale)