* [JSTF] Expose extender glyphs via hb_ot_layout_get_extender_glyphs
The JSTF table is already parsed but never exposed to clients. Extender
glyphs are the most widely populated part of it and are useful for
cursive-script justification implementations that want to prefer a
font-provided extender over the plain U+0640 TATWEEL fallback.
Adds hb_ot_layout_get_extender_glyphs(face, script, language,
start_offset, &count, glyphs) following the standard iterator idiom
used by hb_ot_layout_get_attach_points and friends: NULL for size
probing, inout count for pagination.
Only the script tag is consulted: per the OT spec, extender glyphs live
directly on JstfScript and do not vary by language. JstfLangSys carries
per-language justification priorities, but exposing those is both
harder and less common among fonts than the (already rare) JSTF table
itself; that can be a separate accessor later.
Co-authored-by: Helmut Januschka <helmut@januschka.com>
* [JSTF] Minor simplification by refactoring exposed methods
---------
Co-authored-by: Helmut Januschka <helmut@januschka.com>
Co-authored-by: Behdad Esfahbod <behdad@behdad.org>
* [test] Force the ot shaper in the layout budget tests
test_ot_layout_gpos_mark_base_rescan_budget calls hb_shape() with no
shaper forced, then asserts an OT-specific max_ops trip via
hb_buffer_allocation_successful(). Under the HarfRust shaper
(HB_SHAPER_LIST=harfrust, as the rust CI job re-runs the api suite)
it aborts, because harfrust shapes independently and never reaches
the C-side max_ops paths it tests.
Shape with hb_shape_full(..., {"ot", NULL}) so it exercises the OT
shaper regardless of the configured shaper list, as
test_shape_lookup_budget already does.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [layout] Charge the skip, skipped-record and ligature walks
The per-pass `len / 16` charge does not bound per-position inner work:
the skipping iterator's rescans over default-ignorables, apply_lookup's
walk over a rule's skipped LookupRecords, and match_input /
ligate_input's walk over a ligature's components and marks. Each is a
CPU-DoS a crafted font triggers under the default max_ops.
Charge each on its work path only, so honest shaping is unaffected:
skipping_iterator_t::next/prev charge one op per skip (a first-try
match charges nothing); apply_lookup charges each skipped record;
match_input charges the ligbase backward walk and ligate_input the
mark re-adjust walk, once each.
Reproducers drop from 20 s / 6.8 s / 3.8 s to 0.05 s / 0.003 s /
0.02 s; in-house and aots shaping tests pass with no output change
(the pre-existing text-rendering-tests failures are unchanged).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [layout] Stop matching once the skip/walk budget is spent
The previous commit charged the walks, but the skipping iterator's skip
arm only decremented max_ops; within one pass a tiny aliased font could
still re-run a walk per candidate, per rule or per subtable without bound
(dfrg's harfrust #604 review found the same gaps here).
Flag the buffer unsuccessful when the skip arm spends the budget -- it
still never early-returns, so *unsafe_to stays set for the kern machine --
and stop the loops that repeat walks once it clears: apply_backward,
Ligature::apply, the reverse-chain and mark-base/lig subtable applies,
and context_apply_lookup / chain_context_apply_lookup. apply_forward
already checks successful.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [layout] Enforce the budget in the shared subtable loop
dfrg's re-review (harfrust #604): the per-kind entry guards miss paths
that scan before reaching them -- context format 3, the context/ligature
pre-match scans, cursive and mark-to-mark -- so a lookup aliasing thousands
of subtables restarts a buffer scan at each one. Guard the shared
accelerator apply instead (hb_applicable_t::apply), and drop the
now-redundant reverse-chain and mark-base/lig entry guards it subsumes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
MarkBasePosFormat1 and MarkLigPosFormat1 find a mark's base with a
cache (c->last_base / last_base_until) that is only amortized while
buffer->idx moves forward. A (Chain)Context lookup that recurses into
the mark lookup at input positions out of order resets the cache, so
each application rescans the glyphs from last_base_until to idx from
scratch; on a long run of marks with no base this is quadratic and was
uncharged.
Charge the rescanned span (idx - j) to buffer->max_ops after the
backward search in both lookups, failing the shape when the budget runs
out. A real mark-heavy font pays a negligible amount. Adds a
regression test shaping a Context lookup that recurses to MarkBasePos
at positions 1,0,1,0,...
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FJEXEDJ4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Merge main's active-glyph fast paths and precomputed ClassDef caches
with the dependency and GSUB closure budgets. Charge the fast paths
for the glyphs they visit and the class caches for their ClassDef
scans, preserving both the optimizations and the work limits.
The full Meson suite passes with experimental APIs enabled (300 tests)
and with the default configuration (281 tests). Also syntax-checked
hb-ot-layout.cc with HB_NO_BEYOND_64K.
Assisted-by: Codex
SingleSubstFormat2 already picks, per closure visit, between walking its
whole Coverage and iterating the (usually small) active glyph set. The
Multiple/Alternate/Ligature/ReverseChain closure and depend paths, the
format-1 (Chain)Context closure, and Coverage::intersect_set lacked that
choice, so a nested lookup visited many times over a small active set
re-walked a large Coverage every time, giving quadratic GSUB closure
(and thus subsetting) time.
Add the same get_population()-based fast path to those paths and to
CoverageFormat1/2::intersect_set. Output is byte-identical; only the
per-visit work is bounded.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-KNHDK379.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb_closure_context_t bounded GSUB glyph closure only by counting lookup
visits (HB_MAX_LOOKUP_VISIT_COUNT per round), and forgets which lookups
are done whenever the glyph set grows, so what one visit walks -- through
aliased offsets, many times the table size -- was charged to nothing. A
LigatureSubst with 9000 ligatureSet offsets aliased onto one 64-component
Ligature, re-walked after every one of 1700 Context triggers that each
add a glyph, makes hb-subset --unicodes='*' of an 86 KB font spend ~110 s
of CPU. A ReverseChain/ChainContextFormat3 with aliased backtrack
Coverages is a second way in.
Give the context an int64_t budget (HB_BUDGET_LAYOUT_CLOSURE records, in
the hb_budget_spend() idiom) spent as each closure() implementation walks
its arrays: dispatch() charges a visit its coverage record count;
ligature sets / ligatures / components, sequences, alternates,
single-subst intersections, rule sets and rules, context Coverages (via a
spend_coverages() helper) and the per-rule-set ClassDef walks are each
charged. Coverage and ClassDef gain a get_record_count() helper because
intersects()/intersect_set() are linear in records, not population. Once
the budget is spent, should_visit_lookup()/lookup_limit_exceeded() stop
the closure early, exactly as they do at the visit limit.
The budget lives in the context, so both public closure entry points (also
reached from hb_ot_shape_glyphs_closure() and the subset plan) are covered
with no API/ABI change. Both attack shapes drop to ~1 s and the control
font's closure output is byte-identical; the heaviest real font in the
corpora uses about 1% of the budget. A hostile GSUB now gets a truncated
closure, as one hitting the visit limit already does.
test_ot_layout_lookups_substitute_closure_budget builds the hostile table
in C and drives hb_ot_layout_lookups_substitute_closure() over it.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-J9K92HA9.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
context_closure_recurse_lookups() and context_depend_recurse_lookups()
already hold the rule's input sequence as a width-erased glyph_data_t
view, but for glyph-based rules (ContextFormat::SimpleContext) they
unwrapped the raw pointer and let intersected_glyph() index it as
HBUINT16. That is wrong for the HBUINT24 arrays of
SequenceContextFormat4 / ChainedSequenceContextFormat4: every input
position after the first was read at the wrong bytes, so the nested
lookup was closed over the wrong glyph and its real output never
entered the closure (other glyph ids keep glyphs that can never
appear). Only experimental / beyond-64k builds are affected.
Resolve the glyph via input[seqIndex - 1] for every format and make
intersected_glyph() a plain insert of the value, mirroring its sibling
intersects_glyph() which already takes the resolved glyph and ignores
data. These two call sites were the only users of the
pointer-plus-index convention; 16-bit formats are unchanged, and there
is no API/ABI change.
Adds a regression test under HB_NO_BEYOND_64K: a SequenceContextFormat4
rule "1 2" invoking a SingleSubst 2->3 must close {1, 2} to {1, 2, 3}.
It fails on the unpatched library and passes with the fix.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-IU58QGNT.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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>
Include conditionally referenced lookups in layout collection, feature
closure, and GSUB dependency data. Also retain variation indices used
by FeatureVariations conditions in GSUB and GPOS when remapping the
GDEF variation store.
Tested with the full Meson test suite and targeted HB_NO_VAR builds of
the touched runtime translation units.
Assisted-by: OpenAI Codex <codex@openai.com>
Use the final version 1.4 header with five appended Offset32 fields
instead of the obsolete major-version-2 layout. Honor each nonzero
Offset2 field in preference to its legacy counterpart when reading and
subsetting the table.
Add a binary regression test that gives the legacy and extended glyph
class definitions different values, ensuring the extended field wins.
Testing: meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>