From fe3ab6b23973e96e4a90fe44ade65f9c418ecd3c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Aug 2026 17:25:57 -0600 Subject: [PATCH] [GPOS] Saturate cursive positioning Cursive attachment combines rounded anchors with existing advances and offsets, then may negate the cross-stream displacement. Clamp the floating-point conversions and saturate the integer arithmetic at each stored hb_position_t result. This is part of the complete position-overflow fix for issue #6151. Testing: meson test -C build --print-errorlogs Assisted-by: Codex --- src/OT/Layout/GPOS/CursivePosFormat1.hh | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/OT/Layout/GPOS/CursivePosFormat1.hh b/src/OT/Layout/GPOS/CursivePosFormat1.hh index 41c1f4baa..52fdfbe38 100644 --- a/src/OT/Layout/GPOS/CursivePosFormat1.hh +++ b/src/OT/Layout/GPOS/CursivePosFormat1.hh @@ -184,32 +184,32 @@ struct CursivePosFormat1 /* Main-direction adjustment */ switch (c->direction) { case HB_DIRECTION_LTR: - pos[i].x_advance = roundf (exit_x) + pos[i].x_offset; + pos[i].x_advance = hb_clamp_to ((double) roundf (exit_x) + pos[i].x_offset); - d = roundf (entry_x) + pos[j].x_offset; - pos[j].x_advance -= d; - pos[j].x_offset -= d; + d = hb_clamp_to ((double) roundf (entry_x) + pos[j].x_offset); + pos[j].x_advance = hb_saturate_sub (pos[j].x_advance, d); + pos[j].x_offset = hb_saturate_sub (pos[j].x_offset, d); break; case HB_DIRECTION_RTL: - d = roundf (exit_x) + pos[i].x_offset; - pos[i].x_advance -= d; - pos[i].x_offset -= d; + d = hb_clamp_to ((double) roundf (exit_x) + pos[i].x_offset); + pos[i].x_advance = hb_saturate_sub (pos[i].x_advance, d); + pos[i].x_offset = hb_saturate_sub (pos[i].x_offset, d); - pos[j].x_advance = roundf (entry_x) + pos[j].x_offset; + pos[j].x_advance = hb_clamp_to ((double) roundf (entry_x) + pos[j].x_offset); break; case HB_DIRECTION_TTB: - pos[i].y_advance = roundf (exit_y) + pos[i].y_offset; + pos[i].y_advance = hb_clamp_to ((double) roundf (exit_y) + pos[i].y_offset); - d = roundf (entry_y) + pos[j].y_offset; - pos[j].y_advance -= d; - pos[j].y_offset -= d; + d = hb_clamp_to ((double) roundf (entry_y) + pos[j].y_offset); + pos[j].y_advance = hb_saturate_sub (pos[j].y_advance, d); + pos[j].y_offset = hb_saturate_sub (pos[j].y_offset, d); break; case HB_DIRECTION_BTT: - d = roundf (exit_y) + pos[i].y_offset; - pos[i].y_advance -= d; - pos[i].y_offset -= d; + d = hb_clamp_to ((double) roundf (exit_y) + pos[i].y_offset); + pos[i].y_advance = hb_saturate_sub (pos[i].y_advance, d); + pos[i].y_offset = hb_saturate_sub (pos[i].y_offset, d); - pos[j].y_advance = roundf (entry_y); + pos[j].y_advance = hb_clamp_to (roundf (entry_y)); break; case HB_DIRECTION_INVALID: default: @@ -226,15 +226,15 @@ struct CursivePosFormat1 * Arabic. */ unsigned int child = i; unsigned int parent = j; - hb_position_t x_offset = roundf (entry_x - exit_x); - hb_position_t y_offset = roundf (entry_y - exit_y); + hb_position_t x_offset = hb_clamp_to (roundf (entry_x - exit_x)); + hb_position_t y_offset = hb_clamp_to (roundf (entry_y - exit_y)); if (!(c->lookup_props & LookupFlag::RightToLeft)) { unsigned int k = child; child = parent; parent = k; - x_offset = -x_offset; - y_offset = -y_offset; + x_offset = hb_saturate_neg (x_offset); + y_offset = hb_saturate_neg (y_offset); } /* If child was already connected to someone else, walk through its old