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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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>
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_r3121421428https://github.com/harfbuzz/harfbuzz/issues/5955#issuecomment-4289771142https://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>
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>
* [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
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
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>
`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
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>