Cursive lookups with different flags can create an attachment cycle.
The const cross-offset walker then follows it forever when attaching
a mark. An acyclic chain over len glyphs has at most len - 1 links;
stop at that bound while retaining every valid forward and backward
chain and the existing offset accumulation behavior.
Add an in-house shaping regression instead of a bespoke unit test:
a tiny payload font whose two cursive lookups (one RightToLeft, one
IgnoreMarks) close an A -> B -> C -> A cycle, with a MarkBasePos that
attaches a mark onto C. Shaping ABCD looped forever before the fix and
now terminates. The original hang is reproduced on the unpatched tree;
the patched build shapes it identically under the ot and ft font-funcs.
The full Meson suite passes (274 tests), including shaping.
Reported by Anthropic's OSS Scanner as ANT-2026-PRD7EFA6.
Assisted-by: OpenAI Codex
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Format 2 class values are byte offsets, but ExtendedTypes::offsetToIndex
leaves them unchanged. Use byteOffsetToIndex to convert their sum to an
FWORD index. ObsoleteTypes retains the existing kern format 2 behavior.
Add a synthetic font and shaping regressions covering negative and
positive kerning, the final array entry, zero classes, missing lookup
entries, and disabled kerning.
The shaping regression fails without the fix. The full Meson test suite
passes, and Helvetica Light's LY, AY, Hi, and HH kerning matches CoreText.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6461
Assisted-by: OpenAI Codex
A missing component skipped a fallback ligature but left its partial
component list counted. Later ligatures then used the wrong letters.
Write tentative components at the current offset and advance the
count only after every component has matched.
Add a generated GSUB-less font and two shaping regressions, covering
both the wrong ligature and the valid ligature it displaced, with ot
and ft font functions. All four cases fail before the fix. The full
Meson suite passes (293 tests, 6227 in-house shaping subtests).
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-EMRGZ57Y.
Assisted-by: OpenAI Codex
* Don't divide by zero interpolating duplicate trak tracks
TrackData::get_tracking() brackets the requested track value (always
0 when shaping) between entries i and j and interpolates with
(track - t0) / (t1 - t0). The bracketing scan doesn't assume the
entries are sorted or distinct, so two entries that both have track
value 0.0 end with i = 1, j = 0. That skips the exact-match return
and computes 0/0. The NaN reaches hb_font_t::em_multf(), where the
cast to hb_position_t is undefined (UBSan float-cast-overflow at
hb-font.hh:1167); in practice the advance becomes INT_MIN on x86 and
the tracking is dropped on arm64.
Sanitize accepts such a table, so any font with STAT plus this trak
reaches it from hb_shape(); the CoreText font funcs call the same
getter.
Handle t0 == t1 the way TrackTableEntry::interpolate_at() already
handles equal sizes, by averaging the two values.
Added a 108-byte font to the aat-trak shape tests. It fails without
the fix and passes with it. meson test passes on an ASan+UBSan
debug build.
Assisted-by: Claude
* [aat] Pin duplicate-trak test to ot font funcs
The 108-byte test font only carries STAT and trak, with no head,
hhea or hmtx. The ot font funcs give each glyph a 500 advance, but
FreeType reports 1000 and DirectWrite refuses to load the font, so
the ft and directwrite runs of the test disagreed with the expected
output. The test only needs to exercise the trak interpolation,
so pin it to --font-funcs=ot like other minimal-font tests.
Tested with meson test -C build; the shape suites pass with
FreeType enabled.
Assisted-by: Claude
Ligature substitutions replace consumed components with DELETED_GLYPH.
The deletion helper did not add that sentinel to the cached buffer glyph
set, so a later state machine triggered by the deleted-glyph class could
be skipped when the buffer started with at least four glyphs.
Record DELETED_GLYPH in the active set, as the other replacement helpers
do. Add a synthetic morx font that ligates glyphs 1,2 into 3, then uses a
deleted-glyph transition to enable substitution 4 -> 5. Cover both the
three-glyph scan and the four-glyph cached-set paths.
Found while reviewing harfbuzz/harfrust#542.
Validation: all 292 Meson test groups pass, including the shaping suite.
Assisted-by: OpenAI Codex <noreply@openai.com>
AnchorFormat3 returned each scaled variation delta as an integer before
subtracting the mark and base anchors. Rounding the two deltas separately
can shift the final attachment by an output unit even with an exact
quarter scalar.
Add float-preserving device queries for anchor resolution. Keep hinting
adjustments and ValueRecord queries on the existing integer path, and
retain the final anchor-difference rounding.
Add ten cases with exact scalars, signed deltas, negative and independent
axis scales. Six fail against the original implementation. The full
meson test suite passes (272 passed, one skipped), as does a reduced
HB_NO_VAR/HB_NO_HINTING compile.
Fixes: #6420
Co-authored-by: OpenAI Codex <noreply@openai.com>
Two fuzzed fonts whose GSUB has lookups with types like 3586 (0x0E02)
and 7432 (0x1D08). HarfBuzz's sanitizer rejects the table, so the text
shapes to .notdef glyphs with no lookups applied. HarfRust truncated the
type to u8 and ran them as types 2 and 8 (MultipleSubst and
ReverseChainSingleSubst): a single "A" became 2048 glyphs
(harfbuzz/harfrust#484).
Tested with `meson test -C build` (harfbuzz suites: 252 ok, 8 skipped).
Assisted-by: Claude
Move character mapping, line and glyph metrics, vertical origins, and
glyph names to the new Font model. Use its batched advance APIs while
preserving horizontal rounding and HarfBuzz fallback callbacks.
Share the blob owner with the shaper and remove the metrics lifetime
transmute. Enable two existing vertical variation regressions for
Fontations and add strided batch advance coverage.
Tests: ninja -C build lib; meson test -C build (281 passed, 1 skipped).
Font-only and shape-only cargo checks also passed; the shape-only check
used CARGO_INCREMENTAL=0 after a nightly compiler crash.
Assisted-by: OpenAI Codex
Extend the lookup-variation fixture with a GDEF ItemVariationStore-backed
ConditionValue and a GPOS conditional positioning lookup. This covers
variation-index evaluation, GPOS shaping, and lookup collection while
reusing the existing partial-instancing checks.
Tested with the full Meson suite and OTS validation of the fixture.
Assisted-by: OpenAI Codex <codex@openai.com>
Reduce LookupVariationRecord conditions to false, true, or a residual
condition when axes are pinned or restricted. Fold compound AND, OR,
and NOT conditions, remap value-condition variation indices, and emit a
constant condition when a surviving lookup becomes unconditional.
Extend the test font with a second axis and all condition formats so the
subset tests cover structural, full, and partial instancing behavior.
Tested with the full Meson test suite, targeted Clang HB_NO_VAR and GCC
builds, and OTS validation of the fixture.
Assisted-by: OpenAI Codex <codex@openai.com>
Parse and sanitize the FeatureVariations 1.1 lookup-oriented records.
Resolve their effective lookup sets while constructing the shape-plan
key so cache entries remain exact without retaining raw coordinates.
Handle ADD_DEFAULT_LOOKUPS, multiple matching conditions, and the
interaction with version 1.0 feature substitutions. Keep the existing
public FeatureVariations query API behavior unchanged.
Tested with the full Meson test suite.
Assisted-by: OpenAI Codex <codex@openai.com>
Noto Sans Bengali builds its ra-phala with a format 3 context lookup in
blwf. The Indic shaper asks would_apply() whether that lookup applies;
HarfRust's ContextFormat3 would_apply was off by one and never matched,
so the ra was taken as the base consonant (harfbuzz/harfrust#482).
Font is a 6 KB subset of Noto Sans Bengali (OFL).
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 <codex@openai.com>
A zero-valued PairPos record can select a different, non-zero record
if the second glyph changes, so keep the pair unsafe to concat even
when no positioning was applied.
Likewise, make the ligature second-glyph digest rejection report the
same hazard as the full ligature walk.
Tests: meson test -C build
Port of https://github.com/harfbuzz/harfrust/pull/465
Assisted-by: OpenAI Codex <codex@openai.com>
U+180F MONGOLIAN FREE VARIATION SELECTOR FOUR was added in Unicode
14.0 and has Default_Ignorable_Code_Point=Yes, but
is_default_ignorable() only covered U+180B..180E, so FVS4 was never
hidden and leaked a .notdef into the output.
8c65442069 ("[Unicode 14] Handle U+180F FVS4") added the U+180F case
to _hb_glyph_info_set_unicode_props() and to the Arabic shaper, but
that branch sits inside "if (unicode->is_default_ignorable (u))", so
it has been unreachable since it was written. Extending the range to
U+180B..180F makes it live.
U+180B..180F are all Default_Ignorable_Code_Point per
DerivedCoreProperties.txt, so the range stays contiguous.
Before, with a font with no Mongolian coverage:
$ hb-shape Roboto-Regular.abc.ttf -u U+0061,U+180F
[1=0+1114|0=0@-908,0+0]
Every other default ignorable (U+180B..180E, U+FE00, U+200B) on that
font shapes to [1=0+1114]. After the change U+180F matches them.
Added two cases to mongolian-variation-selector.tests, which already
covered FVS1, FVS2, FVS3 and MVS but not FVS4: U+180F, and U+1810
MONGOLIAN DIGIT ZERO to pin the top of the range so it cannot be
widened by accident.
Tested with "meson test -C build": 254/254 OK, 0 failures. Restoring
the old U+180B..180E fails in-house 6174/6176, and widening it to
U+180B..1810 fails the same way.
Assisted-by: claude-opus-5
Co-authored-by: Dylan Pulver <dylanpulver@users.noreply.github.com>
When the requested direction differs from the script's horizontal
direction, the Graphite2 shaper reverses the buffer before segmenting.
Input cluster values then decrease along the buffer, so assigning each
Graphite group the cluster of its base character can leave earlier
characters outside the resulting cluster map.
Preserve the source span of every Graphite glyph while constructing the
output. At monotone cluster levels, seed each glyph from the minimum
endpoint of that span and use merge_clusters() over each Graphite output
range. Keep the historical base-character behavior at non-monotone
levels.
HarfBuzz cluster values are opaque client labels and can be repeated or
gapped. Merging them can therefore coalesce multiple Graphite layout
groups. Preserve the Graphite group index separately for positioning so
every group's advance is emitted even when its HarfBuzz cluster was
merged. Validate Graphite slot source bounds before indexing the input.
Add shape regressions using a subset of Awami Nastaliq and an API test
with repeated input clusters. The latter used to merge the output
clusters correctly but drop an entire layout-group advance, reducing
the total from 3200 to 1269.
Tested with:
meson test -C build test-graphite2
meson test -C build --suite shape
meson test -C build
Assisted-by: Codex <codex@openai.com>
Co-authored-by: Michael Brown <michael.brown@rubicotech.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Insertion state machines may emit glyphs during the end-of-text transition, when the buffer has no current input glyph. Emit the glyph first in that case and apply AAT metadata to the new output glyph instead of buffer->cur().
Add a regression font whose end-of-text action inserts the AAT deleted-glyph sentinel.
Assisted-by: OpenAI Codex <noreply@openai.com>
Fixes https://github.com/harfbuzz/harfbuzz/issues/4596
See the issue for more details.
Instead of deferring mark positioning to the end of GPOS application, we
now apply cross-direction offsets (y-direction in horizontal text)
immediately and keep applying main-direction (x-direction in horizontal
text) as before.
This is still not 100% compatible with DirectWrite or Core Text (they
apply both directions immediately), but enough to fix the reported
issue.
Based on Behdad’s patch below, but fixes the Noto Nastaliq regression by
resolving the base offset through the whole cursive attachment chain
since cursive offsets are relative the previous glyph and get finalized
only at end of GPOS:
https://github.com/harfbuzz/harfbuzz/issues/4596#issuecomment-2276300688
The remaining failure is not a regression, the new expectation now match
DirectWrite and Core Text.
The tests include a subsetted bug font, as well as two constructed fonts
where curs lookup come before mark ones, once with kern before mark and
with kern after mark, to show that lookup order affects y but not
x-direction.
Non-first pieces of a MultipleSubst now add no extra component, so a
decomposed glyph absorbed into a ligature counts as the single component
it started as, and its marks attach where MarkBasePos would.
Part of https://github.com/harfbuzz/harfbuzz/issues/4969
Correct the ArabicPUATraditional.txt entry for 0xF295 which should be
isolated not final form. Also enable 0xFC43 ligature so the ligature is
actually used.
Fixes https://github.com/harfbuzz/harfbuzz/issues/5984
* [buffer] Fix a typo and doc string
* [buffer] Add merge_grapheme_clusters / merge_out_grapheme_clusters
Cluster merges serve two distinct purposes that require different level
gates:
- Grapheme grouping: combining marks merged into their base cluster.
Correct gate: IS_GRAPHEMES (levels 0 and 3).
New functions: merge_grapheme_clusters / merge_out_grapheme_clusters.
- Monotonicity maintenance: clusters merged to prevent non-monotone
output after ligature formation, reordering, etc.
Correct gate: IS_MONOTONE (levels 0 and 1).
Existing functions: merge_clusters / merge_out_clusters.
Previously both paths shared merge_clusters_impl's single IS_MONOTONE
gate, so GRAPHEMES (level 3) was incorrectly blocked from merging
grapheme clusters. This also caused a regression in the Thai and
Hangul shapers for MONOTONE_CHARACTERS (level 1): when their explicit
== MONOTONE_GRAPHEMES call-site guards were removed in #5069, the
impls' IS_MONOTONE gate no longer protected them.
Gates are now in the inline wrappers in hb-buffer.hh; the _impl
functions are gate-free. hb_form_clusters, CoreText grapheme
detection, and the Thai/Hangul shapers are updated to call the
grapheme-semantic variants. Fixes#5750.
Fixes https://github.com/harfbuzz/harfbuzz/issues/5751
Fixes https://github.com/harfbuzz/harfbuzz/issues/5750
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* [thai] Adjust grapheme merging logic
* [hangul] Tweak grapheme merging
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
* [match-backtrack] Fix syllable-setting logic
If accidentally backtrack_len() was equal idx, we were setting
syllable, even though we want to match backtrack, which shouldn't
match syllable.
I'm surprised how this was not exposed before.
Fixes https://github.com/harfbuzz/harfbuzz/issues/5597
* Always match backtrack per syllable
* Always match lookahead per syllable as well
* Add Indic test for per-syllable backtrack/lookahead matching
More specifically, this asserts that the `kern` table is avoided for
certain shapers, and that we avoid double-spacing in the presence of
`dist` for the same.