test_shape_overlong_cluster_remerge checks the native cluster re-merge op
budget added in hb-buffer.cc, which only the "ot" shaper exercises. Under
HB_SHAPER_LIST=harfrust the harfrust shaper handles clusters itself and
never trips that budget, so the buffer stayed allocation-successful and the
test aborted in the rust CI job. Pin the test to hb_shape_full() with an
"ot" shaper list.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The work budget (max_ops) is meant to bound every buffer pass whose
length the font or text controls, but the same-cluster walks that
re-merge a neighbouring run were never charged:
- the backward merge in delete_glyph() (reached from an empty
MultipleSubst Sequence);
- its copy in delete_glyphs_inplace() (default-ignorable / AAT
glyph deletion);
- the "extend" and cross-buffer continuation loops in
merge_clusters_impl() / merge_out_clusters_impl() (reached from
the Thai/Lao shaper, the normalizer, morx ligatures, and any
ligature/multiple substitution).
Once one long same-cluster run exists, every further merge or
deletion next to it walks the whole run again, so a single hb_shape()
call does O(N^2) work the budget never sees: e.g. U+0E01 followed by
130,000 x U+0E33 takes ~21 s.
Charge the glyphs actually walked to max_ops and fail the buffer when
the budget is gone, following shift_forward()/move_to(), and skip the
walk once the buffer has failed (delete_glyphs_inplace() and the
shaper-level merge_clusters() callers keep calling after a failure).
merge_out_clusters_impl() also gains the "cluster != ..." guards that
merge_clusters_impl() already had, so it no longer walks a run that
already holds the merged value; set_cluster() is a no-op on such a
glyph, so output is unchanged. Verified: default-direction Thai
output is byte-identical to before at sizes that fit the budget, and
pathological inputs now end with hb_buffer_allocation_successful() ==
false, like any other max_ops exhaustion.
Regression test added to test/api/test-shape.c using a stock font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-CQ04GDSH.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Mark-to-mark attachment can accumulate an unbounded cross-direction
offset. Clamp anchor conversion and saturate the immediate addition so
overlong mark clusters stop at hb_position_t limits instead of invoking
signed-overflow undefined behavior.
Add a regression for issue #6151 using 35,000 combining marks.
Testing: meson test -C build --print-errorlogs
Assisted-by: Codex <codex@openai.com>
Based on test from https://code.google.com/p/chromium/issues/detail?id=497578
Currently fails. Basically, if there's a default_ignorable at the
start of text, and font has no space glyph, we remove the default_ignorable,
and that makes the first char in text to correspond to no cluster.
Fix coming.