From 2082751a65eb1c1bb2ef2846ca3ada1ad68cb818 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 7 Jan 2024 22:16:11 -0800 Subject: [PATCH] font/shaper: prevent underflow in multi-cell lig detection Fixes #1251 See the comment for details. --- src/font/shaper/harfbuzz.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/font/shaper/harfbuzz.zig b/src/font/shaper/harfbuzz.zig index 1e6820243..da94afbf5 100644 --- a/src/font/shaper/harfbuzz.zig +++ b/src/font/shaper/harfbuzz.zig @@ -182,7 +182,12 @@ pub const Shaper = struct { // multiple can be replaced. e.g. "===" for (info[i + 1 ..]) |next_info_v| { if (next_info_v.cluster != info_v.cluster) { - break :width next_info_v.cluster - info_v.cluster; + // We do a saturating sub here because for RTL + // text, the next cluster can be less than the + // current cluster. We don't really support RTL + // currently so we do this to prevent an underflow + // but it isn't correct generally. + break :width next_info_v.cluster -| info_v.cluster; } } }