Commit Graph
22474 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 5.5 56b2e5e108 [repacker] Only charge node duplication to the graph work budget
Charging every overflow-resolution iteration its V+L against a budget
of 256 * (V+L) would make a real font that needs more than ~256
iterations fail to repack, though HB_REPACKER_MAX_ITERATIONS (500)
allows it.  Iterations are already capped, so drop the per-iteration
charge and keep only the duplication charge in graph_t::duplicate(),
which bounds the links the graph can grow to (the vertex limit does
not).  Each pass's work is then bounded by the grown graph times the
iteration cap.

The always_recalculate_extensions retry reuses the same graph, clones
included, so not re-arming the budget there is consistent: it counts
links that are still in the graph.

test_work_budget still exhausts the budget and expects both
duplicate() and hb_resolve_graph_overflows() (which must duplicate to
succeed) to return LIMIT_EXCEEDED.  Full meson test: 278 OK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 22:20:30 -06:00
Behdad EsfahbodandClaude Opus 4.8 f51d133546 [repacker] Charge overflow resolution to a per-graph work budget
hb_resolve_graph_overflows() re-checks every link for overflow and
re-sorts the whole graph on every pass, and an isolating pass does
not count as a round.  HB_REPACKER_MAX_ITERATIONS (500) and
HB_REPACKER_MAX_VERTICES (800000) bound neither their product nor the
number of links, which duplicate() copies freely: a 52 KB font whose
90 MarkBasePos subtables share one 8400-anchor BaseArray un-shares it
into 90 copies (756,000 links) and spins ~20 s / ~390 MB before
failing.

Give each graph a work budget proportional to its initial size, in
the HB_SANITIZE_MAX_OPS_FACTOR/_MIN style: graph_t::create() sets
max_ops_ = max(HB_BUDGET_REPACKER_FACTOR * (vertices + links),
HB_BUDGET_REPACKER_MIN).  The resolution loop charges the vertices and
links it is about to walk each pass, and duplicate() charges 1 plus
the links of the clone, both through the existing hb_budget_spend()
idiom.  Exceeding the budget returns the existing LIMIT_EXCEEDED
error, like the other repacker limits.  The budget member persists
across the always_recalculate_extensions retry, so it is not re-armed.

The attack font now fails after ~2.6 s instead of ~20 s; benign
subsets are byte-identical and every local test font that reaches the
repacker uses well under its budget.  test_work_budget in
test-repacker.cc exhausts a small graph's budget and expects
duplicate() and hb_resolve_graph_overflows() to return LIMIT_EXCEEDED.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-M8QKY854.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 21:29:33 -06:00
Behdad EsfahbodandClaude Opus 5.5 488e98dd8c [aat] Share hb_language_from_string()'s canonicalization with ltag (#6610)
* [aat] Share hb_language_from_string()'s canonicalization with ltag

ltag::matches_language() avoids interning the font's tag, but did so
by re-implementing hb_language_from_string()'s canonicalization
(63-byte cap, lowercasing, '_' to '-', stop at other characters) with
its own code, which could drift from canon_map.

Add an internal hb_language_matches_string() in hb-common.cc that
compares a raw string against an hb_language_t through canon_map and
the same length cap, and computes exactly
hb_language_matches (hb_language_from_string (str, len), specific)
without interning str.  matches_language() now calls it.  The length
cap is named once and used by hb_language_from_string() too.

The only edge-case differences from the previous copy are where it
diverged from hb_language_matches(): an empty tag now matches
HB_LANGUAGE_INVALID, and a tag with no canonical characters matches a
language that is empty or starts with '-'.

Testing: meson test -C build (all passing).

Follow-up to #6513

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [aat] Move language matching declaration to hb-algs.hh

Declare hb_language_matches_string() with the internal helpers instead
of in hb.hh. Keep its implementation in hb-common.cc alongside the
shared language canonicalization table.

Validation: meson compile -C build; meson test -C build (278 passed).

Assisted-by: OpenAI Codex

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:30:13 -06:00
Behdad EsfahbodandClaude Opus 5.5 d17c0dbe97 [raster] Fail hb_raster_draw_render() when over the pixel budget (#6616)
#6521 made hb_raster_draw_render() skip the scanline sweep when the
estimated pixel work exceeds the budget, but it still returned a
cleared image, so callers could not tell a budget failure from an
outline that legitimately covers nothing.

Check the budget before allocating the image and return NULL, the
same way render already reports allocation and configuration
failures.  The accumulated edges are still cleared by the existing
scope guard.  All in-tree callers (raster paint masks, hb-raster
utilities) already handle a NULL result.

test_budget_sweep now expects NULL for the over-budget case.  Full
meson test passes.

Follow-up to #6521

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:29:35 -06:00
Behdad EsfahbodandClaude Opus 5.5 9fe4897e97 [face-builder] Drop the parallel sorted_tags; sort once on demand (#6609)
* [face-builder] Sort table tags in get_table_tags() again

Follow-up to #6503.  d52c540c7 kept a sorted copy of the table tags
next to the hash map and maintained it on every
hb_face_builder_add_table() insert (binary search, pre-allocation,
memmove), only so that _hb_face_builder_get_table_tags() would not
have to sort.  That is a second structure to keep in sync with the
map on the hot insertion path for every subset.

Drop the parallel vector and sort the keys in get_table_tags(), as
before.  Serialization (_hb_face_builder_data_reference_blob()) never
used the vector; it sorts its own entries by order and size.  The
65535-table limit goes back to its original tables.has() form; the
other #6503 fixes (axis-range parser, name-override leak, length
bound, reference_blob() recursion) are untouched, and the paging
regression test from d52c540c7 is kept and still passes.

Note that a caller paging through get_table_tags() again pays one
sort per page, which is what ANT-2026-VENZFNXH reported for the
65535-table faces hb_subset_preprocess() can produce.

Tested: meson test -C build (278/278 pass).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [face-builder] Sort table tags once and remember the order

Sorting in every get_table_tags() call brings back the slowdown that
#6503 fixed (ANT-2026-VENZFNXH).  The subsetter pages through a
builder face's tags 32 at a time, so a face with 65535 tables paid
for thousands of full sorts.

Instead of keeping a sorted vector up to date on every insert, build
the sorted tag array the first time it is needed.  Keep it until the
next hb_face_builder_add_table().  The array is published with a
compare-and-swap, so concurrent readers stay safe.  If two readers
race, the loser frees its copy.

Testing: meson test -C build: 278 OK.  Paging through 65535 tags 32
at a time takes 5 ms and returns them sorted.  A table added after a
listing shows up in the next one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:28:45 -06:00
Behdad EsfahbodandClaude Opus 5.5 5e0b0dbb2f [gpu] Trim empty-clip comments (#6608)
The comments added for the empty-clip handling were long-winded
for what the code does.  Shorten them to one line each.

The extents check in hb_gpu_paint_encode() is kept as is: layer
ops are the only ones that accumulate extents, so unset extents
already mean no layer was emitted; a separate flag would only add
state to keep in sync.

No behavior change.  Tested with meson test.

Follow-up to #6483

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:27:12 -06:00
Behdad EsfahbodandClaude Opus 5.5 07cabf6e5b [aat] Drop the per-subtable buffer-pass charge to max_ops (#6605)
charge_buffer_pass() debited buffer->len from max_ops before every
kerx/kern/morx subtable that applies.  It mostly duplicates the
HB_AAT_MAX_SUBTABLES (1024) sanitize cap, which already bounds the
number of passes per table, and it charged the length of a buffer that
morx may have grown against an allowance sized from the input length.

Remove it and its two call sites.  The kerx loop still stops once the
buffer is no longer successful.  The subtable-limit API tests are kept;
they test the sanitize cap, not the charge.

Testing: meson test -C build (all passing).

Follow-up to #6513

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:26:42 -06:00
Behdad EsfahbodandClaude Opus 5.5 5ac43f0a80 [buffer] Restore plain enter() limits; inject the graphite2 fault in the test (#6614)
Follow-up to #6511.  Moving enter()/leave() into HB_SHAPER_EXECUTE
(so hb_shape_plan_execute() gets per-text max_len/max_ops, the
ANT-2026-SUMXXLXH fix) made enter() overwrite the max_len that
test-graphite2-buffer narrows to inject an output-growth failure.
#6511 worked around that in the library: enter() kept any limit
already below the idle default.  That is extra logic in every shape
for the sake of one test.

Restore enter() to simply compute the per-text limits, and have the
test call the plan's shaper_func directly in the failing iteration,
so the max_len it sets is not replaced.  enter()/leave() stay in
HB_SHAPER_EXECUTE, so hb_shape_plan_execute() remains bounded.

The verify path in hb_shape_full() now runs after leave(); that is
fine: verify only reads the shaped buffer's info/pos and shapes
fresh buffers through hb_shape_full(), each of which gets its own
enter()/leave().  It uses no buffer vars or work limits of the
outer buffer.

Tested: meson test -C build (278/278 pass), and a second build with
-Dgraphite2=enabled (280/280 pass, incl. test-graphite2-buffer).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:25:53 -06:00
Behdad EsfahbodandClaude Opus 5.5 73e9d5f054 Revert "[shape-plan] Cache the last shape plan looked up per face (#6550)" (#6618)
This reverts commit 708d59a50.

The one-entry per-face cache doesn't help the common case: with a
single plan per face, the plan is already the first node of the list.
When shaping alternates between keys on one face (LTR and RTL, two
scripts, different features), every call misses the slot.  That costs
an extra key.equal() before the list walk, then a write to the slot.
From several threads, that write bounces the face's cache line
between them on almost every call.  This is the same problem as the
hb_language_from_string() cache from #6549, which is also being
reverted.

A long-lived face with many plans walks the uncapped plan list by
design.  If that becomes a real problem, it should be fixed in the
list itself, not with a slot in front of it.

hb_atomic_t<T *>::set_release(), added in #6549 for these caches,
stays.

Testing: meson test -C build: 278 OK.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:36:35 -06:00
Behdad EsfahbodandClaude Opus 5.5 0c910506de [buffer] Restore simple loops in merge_clusters_impl() (#6615)
#6501 charged the neighboring-cluster walks in merge_clusters_impl()
and merge_out_clusters_impl() to max_ops by wrapping the extension
and cross-buffer continuation loops in an if (successful) block with
their own charges.  These are hot shaping paths, and the restructure
made them harder to follow.

Keep the original loop structure instead: return early once the
buffer has failed (callers such as the Thai shaper keep merging after
that, which is what made the walks quadratic), and move the existing
max_ops charge after the extension loops so that it covers the
extended range plus the cross-buffer continuation.  The cluster !=
guards #6501 added to merge_out_clusters_impl(), matching
merge_clusters_impl(), are kept; without them the Thai SARA AM case
walks the merged run on every call.  delete_glyph() and
delete_glyphs_inplace() are left as they are.

Testing: U+0E01 + 130000 x U+0E33 shapes in 0.04 s LTR / 0.56 s RTL,
same as current main (3.8 s / 5 s without the guards / early return).
test_shape_overlong_cluster_remerge passes; full meson test passes.

Follow-up to #6501

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:33:28 -06:00
Behdad EsfahbodandClaude Opus 5.5 d6d32a9c61 [aat] Fix author line in test-aat.cc header (#6611)
The license header was copied from another file and kept its
"Google Author(s): Garret Rieger" line.  Credit the actual author.

Header-only change; test-aat builds and passes.

Follow-up to #6487

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:32:43 -06:00
Behdad EsfahbodandClaude Opus 5.5 9c2a315301 [vector] Check the INT_MAX bound only after the fast path (#6604)
Follow-up to #6484.  The new `size > INT_MAX` check in
hb_vector_t::alloc() ran before the `size <= allocated` early
return, so every push/resize, including on the shaping hot path,
paid an extra compare and branch.

Do the early returns first and check the bound only when we are
about to reallocate.  The early returns only succeed when size is
at most allocated, which is itself at most INT_MAX, so behavior is
unchanged; the check still precedes the growth loop.  The `exact`
path still clamps size to length before both the shrink check and
the bound check.

Tested: meson test -C build (278/278 pass, incl. test-vector).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:32:12 -06:00
Behdad EsfahbodandClaude Opus 5.5 fc1ad85522 [ft] Take vertical origins from FreeType's bearings again (#6613)
#6499 added caches for the vertical advance and origin, but also
changed what the origin is: its x became half the horizontal
advance (as hb-ot does) instead of FreeType's
horiBearingX - vertBearingX, and a glyph FreeType fails to load got
a cached origin of 0 instead of the callback returning false.  That
changed shaping output for fonts whose vertical bearings are not
centered (e.g. bitmap-only fonts), and stopped the fallback to
h_origins on load failure.

Keep the caches, but cache both the x and y FreeType computes, the
same way as before #6499, and return false on load failure without
caching anything.  Values that don't fit the unsigned cache after
sign normalization are simply not cached.

Testing: meson test -C build passes.  test-ft now checks the
batched origins against FreeType's bearings and that a failed load
returns false on repeat queries.  hb-shape --font-funcs=ft
--direction=ttb output over NotoSansKR plus 80 shape/api test fonts,
at several sizes, a variation, and negative scale (810 runs) is
identical to the commit before #6499; on main 30 of those differed
(aat-feat, chromacheck-cbdt, chromacheck-sbix).

Follow-up to #6499

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:28:24 -06:00
Behdad EsfahbodandClaude Opus 5.5 9e65a95d62 [aat] Share the segment-collection guard between Lookup formats 2 and 4 (#6612)
#6513 made LookupFormat2::collect_glyphs_filtered() stop adding
segments one by one once they are out of order, folding the rest into
a single range.  It did so with an inline copy of the segment logic
instead of the segment's own methods, and LookupFormat4 kept the old
loop, so repeated full-range format-4 segments each still cost a full
pass (bounded only by sanitize's per-byte max_ops on the value arrays).

Move the loop into collect_segments_glyphs_filtered(), shared by both
formats.  It asks each segment type whether it may contribute
(may_match()) and collects through the segment's own
collect_glyphs_filtered().  Format-2 segments check their value against
the filter.  Format-4 segments only check their range, so out-of-order
format-4 segments are folded into a superset without reading their
values.  Format 4's collect_glyphs() now uses the filtered path with an
always-true filter, as format 2's already does.  Sorted tables produce
the same sets as before.

Testing: meson test -C build (all passing).

Follow-up to #6513

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:03:08 -06:00
Behdad EsfahbodandClaude Opus 5.5 6df7f66f94 [CBDT] Cap strikes considered instead of indexing them (#6606)
#6500 made the CBDT accelerator build a per-face (ppem, glyph range)
-> record index at load time, with a strike set/map, a sorted vector,
a walk_ppems fallback and an HB_CBDT_MAX_INDEX_ENTRIES cap, to avoid
walking a huge strike array on every glyph query.  Real fonts have a
handful of strikes, so that machinery costs every CBDT face memory and
load time for the benefit of pathological fonts only.

Remove it and restore the simple CBLC::choose_strike() and
BitmapSizeTable::find_table() lookup path, but only consider the first
HB_CBLC_MAX_STRIKES (256) strikes when choosing one; later ones are
ignored.  ppem is 8-bit, so this never drops a distinct size a real
font could need.  The sbix strike index, the CBDT subsetter's record
map and its image-copy budget from #6500 are kept unchanged.

Adds test_hb_ot_color_png_cbdt_max_strikes, which places the only
usable strike at index 255 / 256 and checks it is found / ignored; it
fails with the cap removed.  Full meson test passes.

Follow-up to #6500

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 17:54:20 -06:00
Behdad Esfahbod 85c9526477 Merge pull request #6603 from harfbuzz/scanner/kerx4-overflow
[kerx] Guard kerx format-4 attach-chain against i16 overflow
2026-11-09 17:36:04 -06:00
Behdad Esfahbod 539a034cf2 Merge pull request #6607 from harfbuzz/fix/revert-language-cache
Revert "[common] Cache the last hb_language_from_string() result"
2026-11-09 17:35:04 -06:00
Behdad Esfahbod a40bb748d1 Merge pull request #6512 from harfbuzz/scanner/varc
[VARC] Bound CPU work in VARC shaping and subsetting
2026-11-09 13:57:59 -06:00
Behdad Esfahbod b457e5d2a1 Merge pull request #6514 from harfbuzz/scanner/cmap
[subset] Bound adversarial cmap work in format 4, per-record collection, and DMAP closure
2026-11-09 13:52:51 -06:00
Behdad Esfahbod 100717c015 Merge pull request #6561 from harfbuzz/scanner/cff-fix
[subset/cff] FDSelect and Encoding-supplement subset correctness fixes
2026-11-09 13:35:10 -06:00
Behdad EsfahbodandClaude Opus 4.8 051a12a37a [cff] Return the sentinel as the end of the last FDSelect range
FDSelect::get_fd_range() is documented to return "one after last glyph
in range", but for the last format-3/4 range FDSelect3_4::get_fd_range()
returned the range's first glyph (62f5ed461 changed it from 0 to that
value to stop an infinite loop, but it is still below every glyph in
the range).  hb_plan_subset_cff_fdselect() assigns that end to its loop
counter, so with a custom old-to-new glyph map the loop re-walks the
last range once per mapped glyph, making CFF1/CFF2 subsetting
quadratic.

The correct end is the FDSelect sentinel: sanitize() guarantees
sentinel > ranges[last].first and sentinel >= num_glyphs (== num_glyphs
for CFF1, >= CharStrings count for CFF2), and the caller only queries
old_glyph < src_num_glyphs and clamps the end to src_num_glyphs, so the
counter now only ever moves forward.  Fixing the accessor (rather than
guarding the loop) keeps the one place that establishes the documented
contract; FDSelect0::get_fd_range() already returns glyph + 1, and the
format-4 instantiation is covered by the same template.

Adds an assertion to the existing test_fd_select_sentinel() in
src/test-cff.cc; it fails before this change.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-CGK397GA.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:18:05 -06:00
Behdad EsfahbodandClaude Opus 4.8 fb58fbe259 [subset/cff2] Plan FDSelect from the real CFF2FDSelect type
cff2_subset_plan::create() cast acc.fdSelect (a CFF2FDSelect) to the
CFF1 FDSelect type for hb_plan_subset_cff_fdselect(), whose
get_fd_range() dispatch knows only formats 0 and 3.  A CFF2-only
format-4 FDSelect therefore reported FD 0 for every glyph, so the
planner kept only Font DICT 0: every retained glyph belonging to
another Font DICT lost that DICT's Private DICT and local subrs, and
when it called a local subr it either lost its outline or drew through
FD 0's subrs with the wrong shape.  The call still succeeded, writing a
single-Font-DICT font.  Format 4 is the only FDSelect format with a
16-bit FD index, so every CFF2 font with more than 256 Font DICTs is
affected.

The planner only needs get_fd_range() and format, so give CFF2FDSelect
its own get_fd_range() dispatching formats 0, 3 and 4, make
hb_plan_subset_cff_fdselect a template over the FDSelect type with
explicit instantiations for CFF1FDSelect and CFF2FDSelect (same pattern
as other explicitly instantiated subset helpers), and drop the cast.
The existing format-4 writer in hb_serialize_cff_fdselect is now
reachable.  Because a CFF2 font with >256 retained FDs can now
legitimately plan format 4, serialize_cff2_to_cff1() rejects that case
(CFF1 has no format 4) instead of emitting an invalid CFF table; with
fewer FDs the downgrade is unchanged.

Adds test_subset_cff2_fdselect_format4, which subsets the format-3 and
format-4 variants of a two-Font-DICT font and requires identical CFF2
output and glyph 2's extents; it fails before this change.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-7RSDR0F0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:18:05 -06:00
Behdad EsfahbodandClaude Opus 4.8 a61e59716f [subset/cff1] Remap Encoding supplement SIDs through sidmap
cff1_subset_plan renumbers every custom SID it emits through sidmap
(charset via plan_subset_charset, Top DICT names via reassignSIDs, FD
names via sidmap[]), and the output String INDEX is serialized from
that map.  plan_subset_encoding was the one emitter that pushed the
source font's SID unchanged into subset_enc_supp_codes, so once an
earlier custom-named glyph was dropped a supplement code named the
wrong glyph, or a string past the end of the renumbered String INDEX.

Look the SID up in sidmap where the supplement entry is recorded.  The
source SID is still used for get_supplement_codes(), which searches the
source Encoding.  This is safe on every path that reaches it:
subset_encoding implies a non-CID font, so plan_subset_charset has
already added each visited glyph's name (sidmap.add is idempotent), and
when the charset is predefined and plan_subset_charset is skipped all
glyph SIDs are standard strings, which sidmap[] returns unchanged.

Adds test_subset_cff1_encoding_supplement with a generated CFF font
(custom names, format-0 Encoding with supplement 98 -> 'second') and
its expected B,C subset; the test fails before this change.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-JORVXUQZ.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:18:05 -06:00
Behdad EsfahbodandClaude Opus 4.8 9c84021391 [VARC] Charge VARC component condition evaluation to the work budget
VarComponent::get_path_at() paid a flat HB_BUDGET_4 per component and
then evaluated the component's Condition tree for free.  ConditionAnd
and ConditionOr children are offsets that may all point at the same
subtree, so the evaluated size of a tree is not tied to its encoded
size: a 1.4 KB ConditionList expands to 51,001 leaf visits per
component, and a 143-byte chain of two-child ConditionAnd nodes to
65,535 node visits, while the glyph budget still admits hundreds of
thousands of such components.  A sub-20 KB font could keep one glyph
extents or draw call busy for minutes, reachable from hb_shape() on
vertical text or combining marks.

Condition::evaluate() is a template shared with FeatureVariations in
GSUB/GPOS, which is evaluated once while building a shape or subset plan
and has no rendering budget, so route the charge through the instancer:
MultiItemVarStoreInstancer::charge_condition() spends HB_BUDGET_1 from
the live budget threaded in for the delta lookups, while
ItemVarStoreInstancer::charge_condition() is a no-op.  Condition::
evaluate() charges one unit per node visited, so every node is counted
even when an And/Or's children share one subtree, and returns false once
the charge fails; the VARC caller already bails when c.budget goes
negative right after the evaluation.  The instancer && guard keeps the
null-instancer callers (e.g. src/test-serialize.cc) safe.

A font whose conditional components do pathological amounts of condition
work now exhausts the glyph budget and renders incomplete output instead
of running for minutes; ordinary fonts spend a few extra units per
conditional component, and GSUB/GPOS condition evaluation is unchanged.
A unit test in src/test-item-varstore.cc pins the per-node charge,
including shared subtrees, and the bail-out once the budget is negative.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-U1J54XX5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:17:50 -06:00
Behdad EsfahbodandClaude Opus 4.8 9f9055ee97 [VARC] Charge MultiItemVariationStore delta lookups per region walked
VarComponent::get_path_at() precharged axisValues.length x coords.length
before MultiItemVariationStore::get_delta(), but the work that call does
is one iteration per entry of the selected MultiVarData's regionIndices
(up to 65535) plus, for each region not yet in the scalar cache, one
evaluation per axis record (up to 65535).  With no variation coordinates
the precharge is zero, so a 148 KB font could drain the 2^24 glyph
budget 65535 times too slowly: about 20 minutes of CPU for a single
extents or draw call, reachable from plain hb_shape() on vertical text
or fallback mark positioning.

Thread the session budget (the same c.budget every other VARC charge
site spends) through the three MultiItemVariationStore::get_delta()
overloads into MultiVarData::get_delta(), which charges (1 + out.length)
per listed region before the walk, and into
SparseVariationRegion::evaluate(), which charges one unit per axis
record before an uncached region is evaluated.  This is the code that
knows the real cost, so the charge is exact rather than an estimate.
The three VARC call sites (axis-value deltas, transform deltas, and the
MultiItemVarStoreInstancer used for component conditions) pass &c.budget
and bail out once it goes negative, replacing the old values x coords
estimates.

All new parameters default to nullptr, so the instancing and subsetting
callers are unaffected; no public API or ABI changes.  A unit test in
src/test-item-varstore.cc pins the exact per-region and per-axis charge
and the bail-out once the budget is negative.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-RV2ORI9U.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:17:50 -06:00
Behdad EsfahbodandClaude Opus 4.8 9ddb3d0f24 [VARC] Bound the glyph records walked during subsetting to the INDEX size
closure_glyphs(), depend() and varc_subset_plan_t::collect_glyphs()
each decode the full glyph record of every glyph id they reach,
assuming every glyph has its own record.  Nothing enforces that:
CFFIndex::sanitize() accepts overlapping glyphRecords offsets, and a
Coverage table may map many glyph ids to the same INDEX entry, so N
glyph ids can resolve to one large record and the walk does N times
that record's work -- quadratic in the font size (44 s for a 245 KB
font), charged to no budget.

In a well-formed table the records are disjoint and each glyph is
visited once, so the bytes of all records walked cannot exceed the
glyphRecords INDEX.  Enforce exactly that invariant where the records
are fetched, in all three walks, failing through each site's existing
idiom.  The remaining work is linear: a component decodes only if its
record holds at least one byte per 64 counted axis values.

In collect_glyphs() this also replaces the saturating sum and the
post-loop data_size != UINT_MAX test, which a 64-bit build bypasses
because hb_unsigned_add_saturate() returns size_t and the sum truncates
into the unsigned data_size (a near-4 GiB total stored as a small
value); the running total is now checked after every addition.

Overlapping VARC records, already malformed per the CFF INDEX spec, now
fail subsetting instead of being accepted; shaping and drawing are
unaffected and valid VARC fonts subset to byte-identical output.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-71PGEDL2.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:17:50 -06:00
Behdad EsfahbodandClaude Opus 4.8 ace1c824d4 [VARC] Use a work stack in closure_glyphs() instead of an hb_set_t (#6566)
closure_glyphs() used an hb_set_t as its work queue, popping the
minimum with get_min() and removing it with del().  del() clears the
bit but keeps the emptied page in the set, and both get_min() and the
while-loop condition rescan from the first page every time, so each pop
rechecks every page emptied by earlier pops.

Components flagged GID_IS_24BIT carry 3-byte glyph ids, and the closure
queues them without checking the face's glyph count (invalid ids are
only dropped afterwards), so a font can spread the queue over all 32768
pages and make each pop cost up to 65536 page checks.  A 400 KB font
whose .notdef composite references one gid per page burns ~6.5 s of CPU
for any subset request, growing ~21 s per further MB.

Replace the set with an hb_vector_t used as a LIFO stack: glyphset
already records which gids have been seen, so nothing is queued twice,
and push()/pop() are O(1) with no page rescans.  The hostile font now
subsets in the same ~0.02 s as a benign font of the same size.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-S2L77GN2.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:17:46 -06:00
Behdad EsfahbodandClaude Opus 4.8 59f4f1a55a [subset] Variable-font instancing subset-output correctness fixes (#6564)
* [instancer] Walk MVAR value records at the source valueRecordSize

MVAR::subset() copied the source valueRecordSize into the output
header but then walked the source array with a typed
VariationValueRecord pointer (8-byte stride) and embedded 8 bytes per
record. For a font whose MVAR uses value records longer than 8 bytes
(valueRecordSize > 8, which the spec and MVAR::sanitize() allow), every
record after the first was read from the wrong offset and the emitted
header described a record array that overlaps the table's own
ItemVariationStore, silently losing metric variations on partial
instancing.

Step through the source records with StructAtOffset at the table's own
valueRecordSize stride, the same way sanitize() and get_var() do, and
declare VariationValueRecord::static_size in the emitted header so it
always matches the 8-byte records that are written. Output for the
usual 8-byte fonts is byte-identical.

Adds a subset regression test (mvar_partial_instance_record_size) built
from NotoSans-VF.abc with its MVAR records re-padded to 12 bytes; its
expected instanced output is byte-identical to the 8-byte
mvar_partial_instance wght=300:600 file and it fails on the unpatched
tree.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-EJUT4BZL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* [subset] Don't retain ItemVariationStore rows the source lacks

The subset plan turned every variation index collected by the COLR,
GDEF and BASE closures into a row to keep, checking only the outer
index against the subtable count and never the inner index against
VarData::itemCount. A font could therefore name tens of thousands of
rows in a VarData whose itemCount is 2, and partial instancing then
sized its work from that inflated row count, allocating
regionIndexCount x rows x 5 bytes (3.2 GB from a 240 KB COLRv1 font).

generate_varstore_inner_maps() now takes the store and keeps only rows
that ItemVariationStore::has_delta_set() confirms exist, and
remap_variation_indices() maps such an index to
HB_OT_LAYOUT_NO_VARIATIONS_INDEX without consuming a new row. That
preserves the runtime meaning of an out-of-range index (delta 0) and
keeps the two functions in step; all consumers already handle the
sentinel. This covers the COLR, GDEF and BASE callers. Well-formed
fonts are byte-identical.

The HVAR/VVAR route noted in the report (its planner builds row maps
itself, one per retained glyph) is left for a follow-up: folding the
missing rows into a shared zero row changes the output form of a
map-less HVAR whose glyph count exceeds the store's itemCount, which
is better landed on its own.

Adds an API regression test (test_subset_colr_phantom_rows) that fails
on the unpatched tree.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-0TLE41I0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:08:56 -06:00
Behdad Esfahbod a01588aad7 Merge branch 'main' into scanner/instancer-fix 2026-11-09 13:06:22 -06:00
ebraminio f33d54ecf9 [subset] Preserve glyph ids for retained glyph-bearing tables (#6586)
The subsetter cannot rewrite tables that refer to glyphs. That includes
legacy kern, AAT (ankr, bsln, just, kern, kerx, lcar, mort, morx, opbd,
prop), Graphite (Glat, Gloc, Silf), JSTF, SVG, LTSH, EBDT/EBLC, and
Apple's Zapf, bdat/bloc, gcid, and hvgl/hvpm tables. When one of these
is retained it is passed through unchanged, so renumbering glyphs makes
its glyph ids stale. Implicitly enable retain-gids in that case.

Make the plan use its own flags after this adjustment so every consumer
sees the effective retain-gids state, and add regression tests covering
AAT, Graphite, and the other unsubsettable glyph tables.

Assisted-by: DeepSeek
2026-11-09 13:04:53 -06:00
Behdad EsfahbodandClaude Opus 5.5 a86ba5f203 [cairo] Remove work-budget accounting (#6602)
hb-cairo hands the actual rendering to cairo, so the work done per
paint operation (clip, gradient, compositing) is cairo's, not ours.
Any count we keep is a guess.  The guesses we had were not good:
022a9e475 charged each paint
(1 + clip + path segments) x max(weight, segments), with a weight of
up to 8192, against HB_BUDGET_GLYPH.  Real fonts blow through that.
For example, hb-view renders the Spain flag in Noto-COLRv1 (U+1F1EA
U+1F1F8) as a blank image, and about ten glyphs in that font go over.

Remove the budget accounting from hb-cairo:

  - Revert 022a9e475 "[cairo] Charge compositing operations to the
    glyph budget", with its test font and generator.
  - Revert 8f3ab5ab8 "[cairo] Share work across nested glyph
    rendering": the per-scaled-font hb_cairo_budget_t, the segment
    charges in the draw callbacks, and the set/get budget callbacks
    on the cairo draw and paint funcs.

Keep paint_color_glyph declining (fd8c9209b), so COLR paints nested
glyphs inline under the decycler and nesting limits of the walk in
progress.  Going through cairo_show_glyphs() again would bring back
the PaintColrGlyph cycle crash, which test_hb_cairo_color_glyph_cycle
covers.  Only the code comment loses its mention of work limits.

Testing: meson test -C build: 299 OK, 1 skipped.  The Spain flag
renders again, and the PaintColrGlyph cycle glyphs in
test_glyphs-glyf_colr_1.ttf render without crashing.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:00:15 -06:00
Behdad Esfahbod 970e231199 [subset] Merge main and resolve COLR regression test conflict
Both branches appended independent regressions to test-subset-colr.c.
Keep the phantom variation-row checks alongside main's overlapping
CPAL palette checks, and register both tests.

Validation: meson compile -C build; meson test -C build.

Assisted-by: OpenAI Codex
2026-11-09 12:52:43 -06:00
Behdad EsfahbodandClaude Opus 4.8 f9b16b40e0 [subset/CPAL] Bound retained color records before copying (#6518)
CPAL::subset() copies the retained colors once per distinct
colorRecordIndices start and later writes distinct-blocks x
retained-colors into the 16-bit numColorRecords, but nothing bounded
that product. CPAL palettes may overlap in the color-record array, so
a well-formed 280 KB font with 20000 palettes of 20000 colors made a
single hb_subset_or_fail() hold ~1.5 GiB of copies and burn ~29 s of
CPU (rebuilt on each out-of-room retry) before failing; smaller
products silently wrapped numColorRecords and the per-palette start
indices in the emitted table. This is a regression from 95ba91721
(#6285, "Share color record blocks between identical palettes").

Fail before copying, at the top of the per-start loop, once one more
block of retained colors could no longer be counted in the 16-bit
numColorRecords, via check_assign() with HB_SERIALIZE_ERROR_INT_
OVERFLOW. This caps the copy-and-hash work, the heap and the
serialized size at 65535 records, and makes the two 16-bit
assignments provably safe, which resolves and removes the
"limit total final size" TODO in serialize(). Palettes that do not
overlap can never reach the limit, since their distinct starts times
numColors already fit in the source numColorRecords.

Trade-off: the bound counts distinct starts, not distinct dedup
blocks, so a font whose many overlapping palettes would all collapse
into a few shared blocks is also rejected past the limit. Pre-#6285
code wrapped on those inputs anyway.

Adds test_subset_cpal_overlapping_palettes asserting the 218-vs-219
palette boundary (65400 records accepted, next rejected).

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-DBBMME51.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 12:43:27 -06:00
Wei-Lun Li 24ded4335b [font] Saturate synthetic bold and glyph origin arithmetic (#6585)
* [font] Saturate synthetic bold and glyph origin arithmetic

#6154 made hb_position_t arithmetic saturate and #6296 did the same
for synthetic_glyph_extents(), but the rest of hb_font_t still used
plain signed arithmetic:

- changed() computed the embolden strength with abs (x_scale), which
  overflows for INT32_MIN, and converted the float product to int
  without a range check. A strength of INT32_MIN could also not be
  negated later on, for negative scales.
- get_font_[hv]_extents(), the advance, origin and contour point
  getters added the strength with += and could overflow.
- add_offset(), subtract_offset() and apply_offset() overflow when
  they apply a large origin, and so do the origin fallbacks in
  apply_glyph_[hv]_origins_with_fallback().
- em_multf() converted its float result to hb_position_t without a
  range check, which is undefined for a value such as an ascender
  above the em at a scale close to INT32_MAX.

Use hb_saturate_add(), hb_saturate_sub() and hb_clamp_to() in these
places, and keep the strength away from INT32_MIN so that negating it
stays defined. Results that fit do not change.

The shift variables that were int are now hb_position_t, since the
saturating helpers deduce one type and int32_t is not int everywhere.

Tested with test-font under UBSan: the new tests fail on the base
commit at hb-font.hh:365, :848, :1154 and :1167, and pass here.

Assisted-by: Claude

* [test] Cover plural origins and synthetic slant saturation

Review feedback: the plural origin getters and the slant
clamp in get_glyph_contour_point were not covered by the
tests, so removing their saturation would still pass.

test_synthetic_bold_saturates now also calls
hb_font_get_glyph_h_origins and hb_font_get_glyph_v_origins
once each and checks both coordinates for INT32_MAX. A new
test_synthetic_slant_saturates sets a slant of 1 on a contour
point one short of INT32_MAX in both axes and checks that x
saturates to INT32_MAX.

Verified by mutation: replacing the plural hb_saturate_add
calls with plain addition makes the first test fail (the
value wraps), and dropping the hb_clamp_to in the slant path
makes the second fail (x comes out as -2). Full
meson test -C build: 270 ok, 0 fail, 7 skipped
(subset+repack, missing repacker dependency; same as the
baseline run for this PR).

Assisted-by: Claude

* [font] Apply the synthetic slant shift before clamping

get_glyph_contour_point clamped the slant shift to
hb_position_t before adding it to x. When x and the shift
have opposite signs and partly cancel, clamping first
changes the result: a contour point at x = -2000000000,
y = 2000000000 with a slant of 2 should land at
x = 2000000000, but came out as 147483647, because the
shift was clamped to INT32_MAX before the addition.

Add the shift first and clamp the sum instead. The
existing saturation case is unchanged: hb_clamp_to
widens to double to do the clamp, so an out-of-range sum
still saturates instead of hitting an undefined
float-to-int conversion.

The new test_synthetic_slant_cancelling covers the
cancelling case. Verified by mutation: restoring the
clamp-first order makes it fail with 147483647, the
reported value. Full meson test -C build: 270 ok,
0 fail, 7 skipped, same as baseline.

Assisted-by: Claude
2026-11-09 11:47:15 -06:00
dependabot[bot] 4cbeba18e1 Bump github/codeql-action/upload-sarif from 4.39.1 to 4.39.3
Bumps [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) from 4.39.1 to 4.39.3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9b3254085494b55a0f7c4c2b3d2d52cc712ce370...33d7b85da1a04171e211befe2c739303b9a4c066)

---
updated-dependencies:
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.39.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-11-09 14:36:46 +02:00
Behdad Esfahbod 9baef4fc09 [aat] Place nodiscard before noinline on kerx action helper (#6600)
* [aat] Remove nodiscard from kerx perform_action

Clang rejects [[nodiscard]] after __declspec(noinline), which is
used by HB_NEVER_INLINE on Windows. Remove HB_NODISCARD from the
kerx format 4 action helper to fix Chromium's Windows build.

Reproduced the failure with Clang 21 and the Windows noinline
spelling; the same syntax check passes after the change.
meson compile -C build and meson test -C build pass (298 passed,
one skipped).

Assisted-by: OpenAI Codex <noreply@openai.com>

* [aat] Restore nodiscard before noinline

Place HB_NODISCARD before HB_NEVER_INLINE so [[nodiscard]] precedes
__declspec(noinline) on Windows. This preserves the return-value
check while avoiding Clang's attribute-ordering error.

Check all six action helpers; only kerx format 4 returns a value.
Keep the other five helpers' void signatures unchanged.

Clang and GCC syntax checks pass in C++11 and C++17. Clang checks
using the Windows noinline spelling also pass in C++17 and C++23.
The full Meson build passes, with 298 tests passed and one skipped.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-11-08 23:12:49 -06:00
Behdad EsfahbodandClaude Opus 4.8 c3fb304549 [subset] Only visit non-default UVS mappings in the DMAP cmap closure
cmap_accelerator_t::closure_glyphs() in the DMAP path expanded, for
every retained variation selector, all of the selector's Default UVS
ranges and resolved each code point with get_variation_glyph(). Any
number of 11-byte selector records may share one Default UVS table and
a 4-byte range covers 256 code points, so the work was bounded by
selectors x covered code points rather than by the table size: a 223 KB
font with 20000 selectors on one 168-range table drove ~860M lookups
and ~49 s of CPU in hb_subset_plan_create_or_fail().

A default mapping can only ever resolve to the nominal glyph, which the
subset plan already retains with the unicode itself, so the closure only
needs the code points that carry a Non-Default UVS mapping in cmap or
DMAP; get_variation_glyph() still decides which table wins for each.
This is exactly what the non-DMAP path (NonDefaultUVS::closure_glyphs)
already does. A collect_variation_non_default_unicodes() accessor is
added alongside the existing collect_variation_unicodes() chain
(VariationSelectorRecord, CmapSubtableFormat14_15, CmapSubtable,
cmap::accelerator_t) and used from the DMAP closure, so the work is one
lookup per 5-byte mapping visited.

No public API or ABI change; hb_face_collect_variation_unicodes() keeps
expanding Default UVS ranges as before, and fonts without DMAP take the
unchanged first branch. The reproducer's plan drops from ~49 s to 0.01 s
with the same 257-glyph result. The separate, older per-record
DefaultUVS::copy() serialization cost (~5.2 s for this font, independent
of DMAP) is left in place.

Adds test_subset_DMAP_shared_default_uvs to test/api/test-subset-cmap.c.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-8RP452C0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 14:36:19 -06:00
Behdad EsfahbodandClaude Opus 4.8 60bd82dcb4 [subset] Bound cmap per-record unicode set collection
When rewriting cmap, the subsetter built one hb_set_t of covered code
points per encoding record. SubtableUnicodesCache keyed those sets by
the record's own offset and collected each with num_glyphs = UINT_MAX,
so a font with many records sharing one full-range format 12 subtable
built one ~1.1M-code-point set per record: ~41 s of CPU, or ~2.1 GB of
memory for a 96 KB input, with nothing but the record count (bounded
only by the sanitizer) limiting the work.

Three changes bound it, all matching how nearby cmap code already works:

 1. Key cached_unicodes by record->subtable, so records sharing a
    subtable share one set (both set_for overloads).
 2. Give the cache a num_glyphs member and collect with it instead of
    UINT_MAX, as the cmap accelerator already does for
    hb_face_collect_unicodes; cmap::serialize fills it from
    plan->source->get_num_glyphs() and create_filled_cache() takes it
    as a parameter, passed as face->get_num_glyphs() for
    hb_subset_preprocess.
 3. Process only the first encoding record of each (platformID,
    encodingID) pair in both cmap::serialize and create_filled_cache
    (variation-selector records exempt). Lookup already sees one record
    per pair and EncodingRecord::copy links later records of a format to
    the first serialized subtable, so this bounds both the number of
    sets built and the _can_drop walk regardless of how many records a
    malformed font repeats, independent of whether they share a subtable.

No public API or ABI change. Output is unchanged for well-formed fonts:
the plan's unicodes are already restricted to gids below num_glyphs, and
valid fonts never repeat a (platformID, encodingID) pair. The attached
reproducer's hostile fonts drop from ~41 s / 2.1 GB to ~0 s / 12 MiB
with byte-identical output.

Adds test_subset_cmap_shared_subtable_many_records and
test_subset_cmap_repeated_encoding_records to
test/api/test-subset-cmap.c.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FSXRDPBT.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 14:36:19 -06:00
Behdad EsfahbodandClaude Opus 4.8 acdd1707a3 [cmap] Bound format 4 collect_unicodes/collect_mapping over overlapping segments
CmapSubtableFormat4::accelerator_t::collect_unicodes() and
collect_mapping() trusted the format's invariant that segments are
sorted and disjoint, so a subtable whose 32766 segments all cover
U+0000..U+FFFE was walked once per segment: ~2.1 billion insertions
(about 30 s of CPU) for a single hb_subset() or
hb_face_collect_nominal_glyph_mapping() call on a 262 KB font.

Both walkers now keep a cursor `next` past the last collected code
point and clamp each segment's start to it, skipping segments that end
before the cursor. Total work per subtable is therefore at most 65536
code points plus one step per segment, mirroring the ordering guard
CmapSubtableLongSegmented::collect_mapping() already has for formats
12/13. The glyphIdArray index is still computed from the raw
startCount[i], so range-offset segments map exactly as before, and
get_glyph() is untouched. Behaviour changes only for malformed
subtables: where sorted segments overlap the earlier segment now wins
the shared code points, and a segment lying wholly inside an earlier
one is ignored.

Adds test_collect_unicodes_format4_overlapping_segments to
test/api/test-collect-unicodes.c.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-GV7L48CF.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 14:36:19 -06:00
Behdad EsfahbodandClaude Opus 4.8 edf8de90d6 [subset] Don't retain ItemVariationStore rows the source lacks
The subset plan turned every variation index collected by the COLR,
GDEF and BASE closures into a row to keep, checking only the outer
index against the subtable count and never the inner index against
VarData::itemCount. A font could therefore name tens of thousands of
rows in a VarData whose itemCount is 2, and partial instancing then
sized its work from that inflated row count, allocating
regionIndexCount x rows x 5 bytes (3.2 GB from a 240 KB COLRv1 font).

generate_varstore_inner_maps() now takes the store and keeps only rows
that ItemVariationStore::has_delta_set() confirms exist, and
remap_variation_indices() maps such an index to
HB_OT_LAYOUT_NO_VARIATIONS_INDEX without consuming a new row. That
preserves the runtime meaning of an out-of-range index (delta 0) and
keeps the two functions in step; all consumers already handle the
sentinel. This covers the COLR, GDEF and BASE callers. Well-formed
fonts are byte-identical.

The HVAR/VVAR route noted in the report (its planner builds row maps
itself, one per retained glyph) is left for a follow-up: folding the
missing rows into a shared zero row changes the output form of a
map-less HVAR whose glyph count exceeds the store's itemCount, which
is better landed on its own.

Adds an API regression test (test_subset_colr_phantom_rows) that fails
on the unpatched tree.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-0TLE41I0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 14:34:15 -06:00
Behdad EsfahbodandClaude Opus 4.8 aad69a017b [instancer] Walk MVAR value records at the source valueRecordSize
MVAR::subset() copied the source valueRecordSize into the output
header but then walked the source array with a typed
VariationValueRecord pointer (8-byte stride) and embedded 8 bytes per
record. For a font whose MVAR uses value records longer than 8 bytes
(valueRecordSize > 8, which the spec and MVAR::sanitize() allow), every
record after the first was read from the wrong offset and the emitted
header described a record array that overlaps the table's own
ItemVariationStore, silently losing metric variations on partial
instancing.

Step through the source records with StructAtOffset at the table's own
valueRecordSize stride, the same way sanitize() and get_var() do, and
declare VariationValueRecord::static_size in the emitted header so it
always matches the 8-byte records that are written. Output for the
usual 8-byte fonts is byte-identical.

Adds a subset regression test (mvar_partial_instance_record_size) built
from NotoSans-VF.abc with its MVAR records re-padded to 12 bytes; its
expected instanced output is byte-identical to the 8-byte
mvar_partial_instance wght=300:600 file and it fails on the unpatched
tree.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-EJUT4BZL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 14:33:10 -06:00
Behdad Esfahbod 71d5df6158 [subset] Fix build after standard trait migration (#6599)
978afca2a removed hb_integral_constant, but four subset table-cache
tag-dispatch sites still used it. Both ordinary and amalgamated
builds fail as a result.

Use std::integral_constant at all four sites to complete the
migration and preserve the existing tag dispatch.

Validation: full Meson build and suite (298 passed, 1 skipped);
GCC and Clang C++11 world amalgamation builds with -Werror; GCC
C++11 HB_TINY core and subset compilation checks.

Fixes: 978afca2a ([meta] Use C++11 standard traits and numeric limits)
Assisted-by: Codex
2026-11-08 14:24:02 -06:00
Behdad Esfahbod 978afca2a9 [meta] Use C++11 standard traits and numeric limits (#6554)
* [meta] Use C++11 standard traits for constants and SFINAE

Replace the duplicated integral constants, boolean tags, enable_if,
and is_same with their C++11 standard counterparts. Use std:: types
at call sites and keep the convenience macros backed by standard traits.

Define hb_match_*::type directly to avoid ambiguity with the type
member inherited from std::integral_constant.

Validation: full Meson suite (298 passed, 1 skipped); six focused GCC
C++11 tests; Clang C++11 compilation checks.

Assisted-by: Codex

* [meta] Use standard type transformations and numeric limits

Keep the short hb_remove_const and hb_remove_reference aliases while
backing them with C++11 standard traits. Remove their unused matching
specializations.

Implement hb_int_min/max using std::numeric_limits. Require integral
types and retain the pointer-minimum specialization returning nullptr.
Parenthesize min/max calls for compatibility with platform macros.

Validation: standard Meson suite (298 passed, 1 skipped); GCC, Clang,
and 32/64-bit MinGW C++11 integer-bound probes with both char signs.
Native probes also link without the C++ runtime at -O0.

The isolated GCC C++11 debug suite passed 276 tests; check-symbols
exposed an existing ARRAY_LENGTH integral_constant value export,
reproduced with the previous commit's hb-meta.hh.

Assisted-by: Codex

* [meta] Remove unused pointer and rvalue reference helpers

Remove hb_add_pointer and hb_add_rvalue_reference along with their
overload helpers. They have no uses in tracked sources.

Validation: meson test -C build (298 passed, 1 skipped).

Assisted-by: Codex
2026-11-08 14:17:24 -06:00
Behdad Esfahbod b70acb123f [aat] Outline state-machine action handlers (#6598)
Keep per-transition bookkeeping in small always-inlined wrappers and
move the larger action bodies into never-inlined perform_action helpers
for all six morx/kerx state-machine contexts. Preserve mark-update order
and early exits when an action fails.

Adding a glyph-set update to ligature deletion enlarged the inlined
driver substantially. Outlining actions avoids duplicating those paths
inside the driver while keeping ordinary transitions cheap. Use the
standard inline attributes directly, including size-optimized builds.

Clang 21 Linux/x86-64 measurements improve the sampled Helvetica Neue,
Menlo, Lucida Grande, and Devanagari Sangam cases by about 1-3% at -O3
and 3-8% at -Oz. The action-heavy Geeza word-list case is a small
tradeoff at -O2.

The full default Meson suite passes: 298 tests passed and one skipped.
Separate -Oz shaping tests and GCC reduced-feature syntax checks pass.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-11-08 14:06:34 -06:00
Wei-Lun Li d1520e8007 [GPOS] Clamp anchor coordinates when converting them from float (#6587)
Anchor coordinates are scaled as float, and apply_cursive_attachment()
and the mark attachment code converted them to hb_position_t with a
plain cast or an implicit conversion. A value out of range for the
target type makes that conversion undefined; on x86 it gives INT32_MIN.
#6154 made the additions around these conversions saturate, but not
the conversions themselves.

With NotoNastaliqUrdu-Regular.ttf at a scale of INT32_MAX, a cursive
anchor scales to 2.23e9, and the glyph ended up with an x_advance of
-2147483648.

Convert with hb_clamp_to(), and negate the cursive cross-direction
offsets with hb_saturate_neg(), since they can now be INT32_MIN.
Results that fit do not change.

Tested with test-shape under UBSan: the new test fails on the base
commit at CursivePosFormat1.hh:141 and passes here. No test reaches
the two conversions in MarkArray.hh; they are changed to match.

Assisted-by: Claude
2026-11-08 12:33:39 -06:00
ebraminio 4ed682d5ce Remove extra inline from static methods (#6582)
* Remove extra `inline` from static methods

Just being defined inside a struct is enough to make them inline.

* Add `inline` to hb-cff-specializer.hh functions

Discovered while writing a custom code having the header included.
2026-11-08 12:16:33 -06:00
Muhammad Abdullah Butt 9644ff2a0f [cmap] Don't clamp format 13 groups to num_glyphs in collect_unicodes (#6597)
CmapSubtableLongSegmented::collect_unicodes() and collect_mapping()
clamp the end of a group so that its glyph ids stay below num_glyphs.
That only makes sense for format 12, where the glyph id increases
across the group. In format 13 every code point of a group maps to the
same glyph, so the clamp cut each group down to a couple of code
points (Adobe Blank 2: 38 code points collected instead of 1,111,998).

Only clamp when the glyph id increases, and fix the clamp itself: it
kept one code point too many, mapping it to glyph num_glyphs.

Fixes https://github.com/harfbuzz/harfbuzz/issues/6591

Assisted-by: Claude
2026-11-07 17:06:07 -06:00
ebraminio ed2e62fa95 [algs] Share pow10 lookup between number parser and SVG serializer (#6596) 2026-11-07 17:03:05 -06:00
Michael Nosthoff 09aff9962a meson: order GPU compilation after shader header generation (#6590)
The shader header custom targets are built by default, but their outputs
are not included in the sources of libharfbuzz-gpu. This allows Ninja to
compile the GPU sources concurrently with shader header generation.

The generator also copies each generated header into the source directory.
The GPU sources use quoted includes, which find these source-tree copies
first. Since the copy truncates its destination before writing, a compiler
running concurrently can read an empty header and report undeclared shader
symbols.

Collect the shader header targets and add them to the GPU library sources.
Meson then orders compilation after those targets have completed, including
their copies back into the source tree.

Keep the existing build-by-default behavior unchanged.

Fixes: b1ad797e5 ("[gpu] Commit stringized shader headers; auto-regenerate like ragel")


Assisted-by: Copilot <223556219+Copilot@users.noreply.github.com>

Signed-off-by: Michael Nosthoff <buildroot@heine.tech>
2026-11-07 16:37:48 -06:00
ebraminio 2f489784c8 [subset] Support longintdict encoding (#6584)
* [test] Expand CFF number font parsing to subsetter encoding roundtrip

* [subset] Support longintdict encoding

It was a TODO for the encoder and this implements it.

* [test] Move roundtrip parse encode to its own function

* [cff] Extract nibble_buffer_t to avoid heap allocated hb_vector_t

* [cff] Use '(size + 1) / 2' buffer size instead of asserting evenness

Address review

* [cff] Minor touches

* [cff] Use idempotent ensure_error instead of set_error

As review
2026-11-07 16:29:39 -06:00