Commit Graph
21401 Commits
Author SHA1 Message Date
Behdad Esfahbod 014ae09d44 [layout] Allocate full GSUB/GPOS v1.2 header
GSUB/GPOS subsetting started by allocating only the base v1.0
header, then jumped directly to lookupList2 for v1.2 tables. That
can pass a pointer beyond the serializer head to extend_min(), which
asserts under fuzzing.

Keep the old incremental allocation for v1.0/v1.1 tables so feature
variation downgrade snapshots can still trim the tail, but allocate
the full version-dependent header before writing v1.2 offsets.

Testing: meson test -C build --suite subset
Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod 336d65cdab [graph] Guard beyond-64k classdef graph tests
The default build has HB_NO_BEYOND_64K enabled, so serializers reject
glyph IDs above 0xffff with an integer-overflow error. Keep the high
glyph ClassDef size checks for beyond-64k builds only.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod 90dcc405a8 [layout] Serialize coverage and classdef from fresh iterators
Coverage and ClassDef serialization use one pass over the input to
choose the compact format, then a second pass to write the selected
format. Reusing the same iterator for both passes left some iterator
types exhausted, which surfaced in test-classdef-graph for high glyph
IDs after the 24-bit forms were added.

Take a fresh iterator view for the sizing pass and another for the
actual serialization.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod 813558d2e9 [gpos] Template mark attachment arrays
MarkBasePos, MarkLigPos, and MarkMarkPos format 2 use nested
MarkArray2, BaseArray2, LigatureArray2, and Mark2Array2 tables
with 24-bit counts and offsets in different combinations.

Template the shared mark records and anchor matrices so format 1
continues to use SmallTypes while format 2 uses the widths specified
for the beyond-64k layout forms. Keep the subset graph wrappers bound
to their existing 16-bit forms.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod cdc1ca9edf [layout] Sanitize lookup lists with their offset width
LookupOffsetList is parameterized by offset width, but its sanitizer
called the 16-bit offset-list base explicitly. Dispatch through the
actual List16OfOffsetTo base so 32-bit lookup-list views use the right
offset element type.

Tested with: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod a86c5a2847 [gpos] Fix subset MarkMark row count
MarkMarkPos subsetting can drop empty Mark2 rows after filtering the
original coverage. Serialize the Mark2Array row count from the kept
coverage instead of the original candidate iterator length.

Tested with: meson test -C build --suite subset
Tested with: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod feb5d2186b [layout] Name GSUB/GPOS typed offset views
Move the repeated typed offset casts in GSUBGPOS sanitize and subset
paths behind local accessors. The table fields keep their existing
reader-facing types, while lookup and feature subsetting can ask for
the specialized list views they need.

Tested with: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod ef538ebafa [graph] Clarify 24-bit layout splitter policy
Update graph splitter comments to document that 24-bit layout formats
are intentionally left unsplit because their relevant offsets are
already widened.

Testing: not run; comment-only change.

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 8a7a5e9baa [graph] Account for 24-bit ClassDef size estimates
Update the ClassDef and Coverage size estimator used by graph
splitting to derive glyph and range widths from the included glyphs
instead of assuming 16-bit table formats. Keep ClassDef size selection
aligned with the serializer heuristic, including class breaks and the
fact that class zero is not encoded in ClassDef tables.

Add high-glyph test cases that compare the estimator against actual
24-bit ClassDef and Coverage serialization sizes.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod fb91f3be90 [graph] Support 24-bit Coverage sanitization
Template the graph Coverage sanitizers on the layout type width and
dispatch formats 3 and 4 through the MediumTypes variants. This lets
graph sanitization accept 24-bit Coverage tables instead of rejecting
those formats outright.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 5f8d73cbe9 [graph] Support 24-bit ClassDef sanitization
Template the graph ClassDef format wrappers on the layout type width
and dispatch formats 3 and 4 through the MediumTypes variants. This
lets graph sanitization accept 24-bit ClassDef tables instead of
rejecting those formats outright.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 5968649782 [layout] Fix 24-bit ClassDef serialization
Select ClassDef formats 3 and 4 by updating the local format value
before storing it in the serialized table. The previous code adjusted
the union format field before overwriting it, so 24-bit glyph IDs could
still serialize as format 1 or 2.

Use the Types integer width for format 1/3 class values and preserve
the matching format tag for empty ClassDef tables.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 6b074f7c4f [gsub] Use typed reverse-chain coverage offsets
Pass the typed coverage offset arrays directly to the shared
backtrack and lookahead match helpers. The skipping iterator already
knows how to extract the underlying 16- or 24-bit offset storage from
OffsetTo arrays, so the reverse-chain apply path does not need raw
pointer casts.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 17946e4648 [gsub] Template alternate and ligature serialization glyph IDs
Allow the builder-style alternate and ligature serialization helpers
to accept either 16- or 24-bit glyph ID array wrappers. Keep one
GlyphID template parameter across each helper and leave the existing
format selection unchanged.

The ligature component-list wrapper is still passed by reference so
its cursor advances across LigatureSet serialization; the glyph data
itself remains read-only when callers pass const array views.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 9e753418a3 [gdef] Document nested beyond-64k offset widths
The GDEF v1.4 header widens several top-level offsets, but not every
nested table changes its own internal offset widths. Document that
AttachList keeps Offset16 internals when reached through attachList2,
and that LigGlyph keeps Offset16 caret value offsets when reached
through LigCaretList2.

Testing: ninja -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod c9e16b1e64 [layout] Widen context coverage offset handling
Use Offset32-based coverage helper dereferences so decoded coverage
offset values work uniformly for both 16- and 24-bit encoded arrays.

Feed ContextFormat3_6 coverage arrays through the layout Types integer,
and template ChainContextFormat3 over Types so its coverage arrays follow
the same structure. The spec adds a sequence-context format 6, but no
corresponding chained-context coverage format; keep chained-context
dispatch limited to formats 4 and 5 and document the discrepancy.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 36e349505a [gsub] Support reverse-chain format 2
Template the reverse-chain single substitution format over the layout
Types and dispatch format 2 for beyond-64k fonts.

Format 2 uses 24-bit coverage offsets and substitute glyph IDs. Keep
the lookahead count 16-bit as specified, even though its coverage
offsets are widened. Match coverage offsets through an Offset32 object
so both 16- and 24-bit offset arrays keep normal null-offset handling.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod dc5d58a9d7 [gsub] Widen format 2 subtable arrays
Use the layout Types array and offset forms for GSUB subtables that
gain 24-bit coverage-indexed arrays in the beyond-64k formats.

This widens SingleSubst substitute arrays, MultipleSubst sequence
offsets, AlternateSubst alternate-set offsets, LigatureSubst
ligature-set offsets, and the LigatureSet offsets to Ligature
tables while preserving the nested 16-bit counts required by the
spec.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 373ff59709 [layout] Widen chained context rule-set offsets
Use the layout Types for chained context rule-set arrays and
ChainRuleSet offsets. For class-based formats, use a named
ChainClassRuleSet wrapper so the 24-bit surrounding offsets do not
leak as a second template argument at the call site.

This brings ChainedSequenceContextFormat4 and Format5 in line with
the spec's 24-bit counts and offsets while keeping class-rule
payloads in their 16-bit class-value form.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 77acc39460 [layout] Widen sequence context rule-set offsets
Use the layout Types for sequence context rule-set arrays and
RuleSet offsets. For class-based formats, use a named ClassRuleSet
wrapper so the 24-bit surrounding offsets do not leak as a second
template argument at the call site.

This brings SequenceContextFormat4 and Format5 in line with the
spec's 24-bit counts and offsets while keeping class-rule payloads
in their 16-bit class-value form.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 770cc08a26 [layout] Support sequence context format 6
Template the coverage-based sequence context format over layout
Types and dispatch format 6 through the MediumTypes instance.

This matches the spec's wider coverage-offset variant while keeping
formats 1 through 5 unchanged.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 7978af46e7 [layout] Support GDEF version 1.4 header
Fold the GDEF versioned header fields back into GDEF and select
active offsets from the table version.

Version 1.4 now honors the spec's 32-bit offset2 fields when they
are present.  LigCaretList is templated over layout Types so the
version 1.4 LigCaretList2 layout can use the 32-bit coverage offset,
24-bit glyph count, and 24-bit LigGlyph offsets.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod a1a1002e59 [layout] Fold GSUB/GPOS version handling into header
Move the GSUB/GPOS versioned header fields back into GSUBGPOS
and select the active ScriptList, FeatureList, and LookupList
offsets from the table version.

Version 1.2 now uses the spec's 32-bit offset2 fields when they
are present, while the common list internals remain the existing
16-bit layout structures.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod e9289735f2 [base] Support BaseCoord format 4
Add the BASE BaseCoord format 4 dispatch arm. The format mirrors
format 2, but stores the reference glyph as a 24-bit glyph ID for
fonts with an extended glyph repertoire. Share the implementation
through a Types-templated format pair.

The subsetting path remaps the widened reference glyph in the same
way format 2 remaps its 16-bit reference glyph.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod eb8d87f024 [beyond-64k] Preserve CursivePos format when subsetting
CursivePos format 2 reuses the templated format-1 body with wider
fields. Preserve the source format when serializing subsets so a format-2
subtable is not emitted with a format-1 tag.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 4997b9f75c Revert some AI noise
Broke some access that was guarded behind hb_barrier()
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 533452d0d6 [beyond-64k] Update SinglePos / PairPos for latest proposal 2026-06-05 12:34:51 +02:00
Behdad Esfahbod 435a67417e [beyond-64k] Add CursivePosFormat2 2026-06-05 12:34:51 +02:00
Behdad Esfahbod 0932bbc45c [beyond-64k] Update PairPosFormat3 to latest proposal 2026-06-05 12:34:51 +02:00
Behdad Esfahbod 155c19c216 [beyond-64k] Add SinglePos formats 3/4 2026-06-05 12:34:51 +02:00
Garret Rieger 8647a429ce Fix subset fuzzer timeout. (#6019)
https://oss-fuzz.com/testcase-detail/5440786836815872
2026-06-04 04:37:23 -06:00
Khaled Hosny 56feae4035 14.2.1 14.2.1 2026-06-02 14:30:59 +03:00
Behdad Esfahbod 8beb229a4c [gen-tag-table] Generate bytes instead of str in rust output (#6017) 2026-06-02 03:11:23 -06:00
Fuqiao Xue 6dda1a083c Add HB_SCRIPT_KATAKANA_OR_HIRAGANA (#5995)
* Add HB_SCRIPT_KATAKANA_OR_HIRAGANA

Fix #1473.

* Refactor HB_SCRIPT_KATAKANA_OR_HIRAGANA
2026-06-02 02:33:52 -06:00
Behdad Esfahbod 2575326527 [rust] Bulk-populate HarfRust input buffer (#6016)
Use the HarfRust bulk UnicodeBuffer glyph-info append API to populate
the shaping buffer from HarfBuzz glyph infos after one slice cast. This
avoids per-codepoint add calls in the HarfBuzz-to-HarfRust bridge.

Testing: ninja -C build src/rust/libharfbuzz_rust.a

Assisted-by: OpenAI Codex
2026-06-02 01:46:23 -06:00
Behdad Esfahbod a4eb9e25d3 [rust] Avoid parsing HarfRust language tags (#6015)
HarfBuzz language tags are already available as C string bytes.
Pass those bytes directly to HarfRust Language::new instead of
converting through UTF-8 and FromStr.

Testing: ninja -C build src/rust/libharfbuzz_rust.a

Assisted-by: OpenAI Codex
2026-06-01 10:35:24 -06:00
Behdad Esfahbod 97650e50e2 [rust] Use SmallVec for HarfRust features (#6014)
Most shaping calls pass maximum a couple of user features. Store the
converted HarfRust feature list in a SmallVec with the same inline
capacity that HarfRust uses for shape-plan user features, avoiding
a heap allocation for common cases.

Testing: ninja -C build src/rust/libharfbuzz_rust.a

Assisted-by: OpenAI Codex
2026-06-01 09:53:23 -06:00
Behdad Esfahbod 8987443bd3 [rust] Bulk-copy HarfRust shape results (#6013)
HarfRust glyph infos and positions are layout-compatible with the
corresponding HarfBuzz buffer structs. Assert that size, alignment,
and visible field offsets match, then copy both arrays directly into
the HarfBuzz buffer instead of translating each glyph field-by-field.

Also, don't truncate hb buffer before resizing it to populate. This
would not zero the private fields (var1/var2, var), but that's not
visible to user nor used later.

Assisted-by: OpenAI Codex
2026-06-01 08:49:52 -06:00
Behdad EsfahbodandClaude Opus 4.8 d639197ed5 [COLR] Fix glyph extents for .notdef in COLRv1 fonts (#6012)
get_base_glyph_paintrecord() looked up the BaseGlyphList with the
reference-returning bsearch(), which yields the all-zero Null object
when the glyph is absent, and then rejected non-matches by comparing
record->glyphId against the requested gid. For glyph 0 the Null
object's glyphId (0) equals the requested gid, so the sentinel was
taken for a real record. .notdef then resolved to a bogus empty paint,
and COLR::get_extents() returned success with 0,0,0,0 instead of
letting hb_ot_get_glyph_extents() fall back to the glyf outline.

Use bfind(), which reports presence directly, so a missing glyph
(including glyph 0) returns nullptr and extents fall back correctly.

This surfaced as a mark-positioning difference: fallback mark
positioning centers a mark using the base and mark glyph extents, so a
.notdef mark over a space was positioned differently from shapers that
report the real outline extents (e.g. fontations/HarfRust).

Testing:
- test/api/test-extents.c: glyph 0 (.notdef, has an outline) now
  reports its outline extents; updated the expectation accordingly.
- b/util/hb-shape Noto-COLRv1.ttf -u 0020,0650 now matches
  --font-funcs=fontations.
- meson test -C build  (246 passed, 1 skipped)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 03:23:05 -06:00
Behdad Esfahbod 27734f01dc Fix unused-warning error
https://github.com/harfbuzz/harfbuzz/pull/6009#issuecomment-4590976488
2026-06-01 10:54:05 +02:00
Behdad Esfahbod 0efc579fc4 [config] Fix CFF closure with HB_NO_DRAW (#6009)
HB_NO_DRAW only disables the draw-dependent OT-font CFF extents
path.  It should not imply full HB_NO_CFF for downstream builds
that independently disable CFF subsetting.

Keep the HB_TINY behavior by making HB_NO_CFF conditional on the
combination of HB_TINY and HB_NO_DRAW.  Also avoid calling the CFF2
instance-metrics helper when OT-font CFF support is disabled, since
that helper needs the CFF2 extents implementation.

Context:
https://github.com/harfbuzz/harfbuzz/pull/5958#discussion_r3121421428
https://github.com/harfbuzz/harfbuzz/issues/5955#issuecomment-4289771142
https://github.com/harfbuzz/harfbuzz/issues/5955#issuecomment-4345573851

Tested by compiling src/harfbuzz-subset.cc directly with
-DHB_NO_DRAW -DHB_NO_SUBSET_CFF and checking the CFF2 extents symbol
is no longer undefined.  Also direct-compiled src/harfbuzz.cc with the
same defines, plus src/harfbuzz-subset.cc for plain HB_TINY and
HB_TINY with HAVE_CONFIG_OVERRIDE_H using util/gpu/web.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-06-01 02:32:21 -06:00
Dominik RöttschesandBehdad Esfahbod 30bde663e7 Pass codepoints for context directly to HarfRust shaper (#6008)
Avoid unnecessary round-trip of converting pre- and post-context from
Unicode codepoints to UTF-8 in C++ (hb-harfrust.cc) and back to Rust
&str (and eventually back to codepoints) in Rust (shape.rs).
Instead, use the new codepoint-based context setters in HarfRust.

Verified locally against CJK_article.html blink_perf menchmark to
gain approximately 2-4%.

Requires https://github.com/harfbuzz/harfrust/pull/371 and a newly
released HarfRust version.

Assisted-by: Google Antigravity

Co-authored-by: Behdad Esfahbod <behdad@behdad.org>
2026-06-01 02:32:01 -06:00
Behdad Esfahbod bc4cd305ca [rust] Use new harfrust GlyphFlags getter (#6011)
* [rust] Reinstate commented-out git branch for harfrust

For development purposes.

* [rust] Use new HarfRust GlyphFlags getter

Faster.

* [rust] Pin to new harfrust 0.8.2
2026-06-01 02:23:26 -06:00
Behdad Esfahbod fd707f8151 [fontations] Map default variations
https://github.com/servo/servo/pull/38707#issuecomment-4587826343
2026-05-31 21:26:19 +02:00
Behdad Esfahbod 2353415a37 [rust] Reinstate commented-out git branch for harfrust
For development purposes.
2026-05-30 23:23:59 +02:00
Behdad Esfahbod e020ac487e [buffer] Harden verification after non-monotone clusters (#6010)
When buffer verification detects non-monotone clusters, skip the
unsafe-to-break and unsafe-to-concat checks that rely on monotone
cluster order.  Keep reporting the monotone-cluster failure as the
underlying verifier error.

Also turn the unsafe-to-break text range assertion into a verifier
failure so malformed intermediate verifier state does not abort the
process.

Testing:
meson test -C build

Assisted-by: OpenAI Codex
2026-05-30 08:48:03 -06:00
Behdad Esfahbod abc3b1a363 [avar] Avoid float-to-int overflow UB in avar2 mapping
map_coords_16_16() converted roundf(delta * 4) back to int without
bounding the float first. With attacker-controlled avar2 long-word
(32-bit) ItemVariationStore deltas, delta * 4 can exceed INT_MAX, and
the implicit float-to-int conversion is undefined behavior per the C++
standard (out-of-range floating-to-integral conversion). The result was
clamped immediately afterwards, so there was no memory-safety impact,
but the conversion itself trips UBSan.

Clamp the float to the 16.16 normalized range before the conversion so
the narrowing can never go out of range.

Fixes: https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-xxfv-x2x5-8992

Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-30 15:41:53 +02:00
Takeru Suzuki 689383d05b [subset] keep East Asian spacing palt by default (#6007)
`palt` (Proportional Alternate Widths) is widely used in Japanese
typography but was not retained in the default subset layout features,
unlike its vertical counterpart `vpal` and the closely related `halt`
/ `vhal` / `chws` / `vchw` already kept by default. As a result,
subsetting silently stripped `palt` data, and downstream CSS
`font-feature-settings: "palt"` had no effect.

Add `palt` to the default layout features list alongside the other
East Asian spacing features.

Verified locally with `meson test -C build` (240/240 OK, 0 failures)
and by subsetting NotoSansJP-Bold.ttf with `hb-subset`: `palt` is
stripped on main and retained with this patch, while the other CJK
spacing features (`halt`, `vpal`, `vhal`) are unaffected.

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

Assisted-by: Claude
2026-05-29 03:19:18 -06:00
Behdad EsfahbodandChad Brokaw 77abf89986 [harfrust] Honor hb font funcs during shaping (#6002)
Wire the HarfRust shaper through the active hb_font_t callback
surface so custom hb_font_funcs_t are respected during shaping.
Add a harfrust-specific test-shape invocation to cover that path.

Tested: meson test -C build test-shape-harfrust
Tested: HB_SHAPER_LIST=harfrust meson test -C build harfbuzz:shape_threads
Tested: HB_SHAPER_LIST=harfrust meson test -C build test-shape
Assisted-by: OpenAI Codex

---------

Co-authored-by: Chad Brokaw <cbrokaw@gmail.com>
2026-05-28 13:33:21 -04:00
Qunxin Liu 1e434eb7fd [subset-repack] increase the MAX_SPACES limit (#5996)
This fixes: https://github.com/harfbuzz/harfbuzz/issues/5980
2026-05-27 16:43:47 -06:00