From db981a8baff024ce9a6bf7944bb9dcc8c4d77709 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 5 Sep 2026 14:44:39 -0600 Subject: [PATCH] [gsubgpos] Preserve concat hazards at end of input (#6238) The RuleSet fast paths filtered out rules requiring another glyph when the skipping iterator reached the end of the buffer. Unlike the normal rule walk, that early return did not record the resulting unsafe-to-concat range. Keep the end-of-input optimization, but track filtered rules and mark their concat hazard before returning. Cover both contextual and chained contextual rule sets with a five-rule font that forces the fast paths. Assisted-by: OpenAI Codex --- src/hb-ot-layout-gsubgpos.hh | 33 +++++++++++------- ...0495f304286cb87964400d03752ae5bc5622b9.ttf | Bin 0 -> 948 bytes .../in-house/tests/unsafe-to-concat.tests | 2 ++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 test/shape/data/in-house/fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 1695b1d8c..73af70f06 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -3351,7 +3351,7 @@ struct RuleSet skippy_iter.set_glyph_data ((HBUINT16 *) nullptr); unsigned unsafe_to = (unsigned) -1, unsafe_to1, unsafe_to2 = 0; hb_glyph_info_t *first = nullptr, *second = nullptr; - bool matched = skippy_iter.next (); + bool matched = skippy_iter.next (&unsafe_to1); if (likely (matched)) { if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx])) @@ -3373,16 +3373,22 @@ struct RuleSet } else { - /* Failed to match a next glyph. Only try applying rules that have - * no further input. */ - return_trace ( + bool unsafe_to_concat = false; + bool ret = + hb_iter (rule) | hb_map (hb_add (this)) - | hb_filter ([&] (const Rule &_) { return _.inputCount <= 1; }) + | hb_filter ([&] (const Rule &_) + { + if (_.inputCount <= 1) return true; + unsafe_to_concat = true; + return false; + }) | hb_map ([&] (const Rule &_) { return _.apply (c, lookup_context); }) | hb_any - ) ; + if (unsafe_to_concat) + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1); + return_trace (ret); } matched = skippy_iter.next (); if (likely (matched)) @@ -4939,7 +4945,7 @@ struct ChainRuleSet skippy_iter.set_glyph_data ((HBUINT16 *) nullptr); unsigned unsafe_to = (unsigned) -1, unsafe_to1, unsafe_to2 = 0; hb_glyph_info_t *first = nullptr, *second = nullptr; - bool matched = skippy_iter.next (); + bool matched = skippy_iter.next (&unsafe_to1); if (likely (matched)) { if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx])) @@ -4961,21 +4967,24 @@ struct ChainRuleSet } else { - /* Failed to match a next glyph. Only try applying rules that have - * no further input and lookahead. */ - return_trace ( + bool unsafe_to_concat = false; + bool ret = + hb_iter (rule) | hb_map (hb_add (this)) | hb_filter ([&] (const ChainRule &_) { const auto &input = StructAfter (_.backtrack); const auto &lookahead = StructAfter (input); - return input.lenP1 <= 1 && lookahead.len == 0; + if (input.lenP1 <= 1 && lookahead.len == 0) return true; + unsafe_to_concat = true; + return false; }) | hb_map ([&] (const ChainRule &_) { return _.apply (c, lookup_context); }) | hb_any - ) ; + if (unsafe_to_concat) + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1); + return_trace (ret); } matched = skippy_iter.next (); if (likely (matched)) diff --git a/test/shape/data/in-house/fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf b/test/shape/data/in-house/fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf new file mode 100644 index 0000000000000000000000000000000000000000..44a494fb508894b018c75d6949e5c386e05fb5cd GIT binary patch literal 948 zcmaJGP-p2@rM6=}&sIqfj#&OputXtkr> zpol_W^<*MG^SI9-d4QVtpdV;0ph?mxx3#98rtRn)SKoa$MY z{meeQE*Ab11yp)n3M1_EZUdYm<1U2(RxaUe4+pH?teUosQe%_I#%;S8H#$wT$;}Pg zu!xWnStLXjv8yd|Zt&@vT-g*e$8WUXqTKx?%D9XxJmFQ`BNu0b6uk>ISDjx*=x?7V z7B!x~o~*|hsoSpQ&A5uoihbYtWsSM$Dj~bSa)ji=I7iKC+@gxyp@bm0XOH|FOHID^ xwUR@UMMd$j2Wl7Tw}LshB6{LlwB(=iuXe!X%?{U!eXP`D(&2X~@s&kG{R4D