From d36a16f8ca5f97f0c9cebfaf5cf2d0eb362c7f17 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Aug 2026 17:19:26 -0600 Subject: [PATCH] [GPOS] Saturate propagated attachment offsets Deferred mark and cursive attachment propagation combines offsets with the advances between attached glyphs. Use saturating arithmetic for each position update instead of relying on signed overflow behavior. This removes the historical overflow from the function that issue #6151 moved out of Chromium's sanitizer exemption. Testing: meson test -C build --print-errorlogs Assisted-by: Codex --- src/OT/Layout/GPOS/GPOS.hh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/OT/Layout/GPOS/GPOS.hh b/src/OT/Layout/GPOS/GPOS.hh index e08eb9155..754823501 100644 --- a/src/OT/Layout/GPOS/GPOS.hh +++ b/src/OT/Layout/GPOS/GPOS.hh @@ -101,16 +101,16 @@ propagate_attachment_offsets (hb_glyph_position_t *pos, if (type & GPOS_impl::ATTACH_TYPE_CURSIVE) { if (HB_DIRECTION_IS_HORIZONTAL (direction)) - pos[i].y_offset += pos[j].y_offset; + pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[j].y_offset); else - pos[i].x_offset += pos[j].x_offset; + pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[j].x_offset); } else /*if (type & GPOS_impl::ATTACH_TYPE_MARK)*/ { if (HB_DIRECTION_IS_HORIZONTAL (direction)) - pos[i].x_offset += pos[j].x_offset; + pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[j].x_offset); else - pos[i].y_offset += pos[j].y_offset; + pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[j].y_offset); // i is the position of the mark; j is the base. if (j < i) @@ -119,13 +119,13 @@ propagate_attachment_offsets (hb_glyph_position_t *pos, * And currently the only way in OpenType. */ if (HB_DIRECTION_IS_FORWARD (direction)) for (unsigned int k = j; k < i; k++) { - pos[i].x_offset -= pos[k].x_advance; - pos[i].y_offset -= pos[k].y_advance; + pos[i].x_offset = hb_saturate_sub (pos[i].x_offset, pos[k].x_advance); + pos[i].y_offset = hb_saturate_sub (pos[i].y_offset, pos[k].y_advance); } else for (unsigned int k = j + 1; k < i + 1; k++) { - pos[i].x_offset += pos[k].x_advance; - pos[i].y_offset += pos[k].y_advance; + pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[k].x_advance); + pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[k].y_advance); } } else // j > i @@ -134,13 +134,13 @@ propagate_attachment_offsets (hb_glyph_position_t *pos, * to a base after it in the logical order. */ if (HB_DIRECTION_IS_FORWARD (direction)) for (unsigned int k = i; k < j; k++) { - pos[i].x_offset += pos[k].x_advance; - pos[i].y_offset += pos[k].y_advance; + pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[k].x_advance); + pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[k].y_advance); } else for (unsigned int k = i + 1; k < j + 1; k++) { - pos[i].x_offset -= pos[k].x_advance; - pos[i].y_offset -= pos[k].y_advance; + pos[i].x_offset = hb_saturate_sub (pos[i].x_offset, pos[k].x_advance); + pos[i].y_offset = hb_saturate_sub (pos[i].y_offset, pos[k].y_advance); } } }