Add a 100,000-character Japanese shaping corpus derived from Natsume
Soseki's copyright-expired Wagahai wa Neko de Aru. Split the sample
into pure Han, Hiragana, and Katakana runs, with Inherited characters
allowed within a run and Common characters omitted.
Document the Aozora Bunko source, reuse terms, source checksum, and
transformations in perf/texts/COPYING.
Testing: meson test -C build (274 tests passed)
Assisted-by: OpenAI Codex
U+180F MONGOLIAN FREE VARIATION SELECTOR FOUR was added in Unicode
14.0 and has Default_Ignorable_Code_Point=Yes, but
is_default_ignorable() only covered U+180B..180E, so FVS4 was never
hidden and leaked a .notdef into the output.
8c65442069 ("[Unicode 14] Handle U+180F FVS4") added the U+180F case
to _hb_glyph_info_set_unicode_props() and to the Arabic shaper, but
that branch sits inside "if (unicode->is_default_ignorable (u))", so
it has been unreachable since it was written. Extending the range to
U+180B..180F makes it live.
U+180B..180F are all Default_Ignorable_Code_Point per
DerivedCoreProperties.txt, so the range stays contiguous.
Before, with a font with no Mongolian coverage:
$ hb-shape Roboto-Regular.abc.ttf -u U+0061,U+180F
[1=0+1114|0=0@-908,0+0]
Every other default ignorable (U+180B..180E, U+FE00, U+200B) on that
font shapes to [1=0+1114]. After the change U+180F matches them.
Added two cases to mongolian-variation-selector.tests, which already
covered FVS1, FVS2, FVS3 and MVS but not FVS4: U+180F, and U+1810
MONGOLIAN DIGIT ZERO to pin the top of the range so it cannot be
widened by accident.
Tested with "meson test -C build": 254/254 OK, 0 failures. Restoring
the old U+180B..180E fails in-house 6174/6176, and widening it to
U+180B..1810 fails the same way.
Assisted-by: claude-opus-5
Co-authored-by: Dylan Pulver <dylanpulver@users.noreply.github.com>
Error handling in repacker is in rough shape. Many of the methods are fallible, but often the return values aren't being checked for error state.
To help address this I thought it might be useful to introduce a result type similar to Result<> in rust (or std::expected) that would force callers to deal with errors in the returns.
This PR introduces hb_result_t<OkVal, ErrVal>.
Assisted by: Gemini
FreeType requires face creation and destruction on a shared
FT_Library to be serialized. Protect the lazily-created static library,
its reference count, and its internally-owned faces with a lazy mutex.
Keep caller-owned FT_Library instances outside the new lock, and add a
multithreaded regression test for blob-backed faces and font funcs.
Tests: meson test -C build (272/272 passed)
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6224
Assisted-by: OpenAI Codex <codex@openai.com>
sscanf("%lf") for --font-size, --embolden, --font-extents and
--margin follows the environment LC_NUMERIC set by setlocale(LC_ALL,
""), so "10.5" parses as 10 under a comma-radix locale. Force
LC_NUMERIC to C after the environment locale is applied so these
options use a '.' radix, like g_ascii_strtod already does for --width.
context_depend_lookup and chain_context_depend_lookup build the
input-position glyph sets with for (i = 0; i < inputCount - 1; i++),
so a Rule with inputCount 0 (what a null rule offset resolves to)
underflows the bound to UINT_MAX and reads past the object into the
Null pool. Rewrite both loops as i + 1 < inputCount, matching the
guarded inputCount handling used everywhere else in the file. Reached
from hb_subset_depend_from_face_or_fail on a crafted GSUB context
rule; seed added under test/fuzzing/fonts.
The Win1256 fallback is a static GSUB recipe selected by a narrow glyph-ID
signature; it does not call a Windows API. Enable it outside Windows too,
while retaining HB_NO_WIN1256 as an explicit opt-out.
Tested: meson test -C build; build with -DHB_NO_WIN1256
Assisted-by: Codex <codex@openai.com>
The HarfRust Arabic fallback cache now supports no-std builds. Emit the
presentation-form and ligature data without a std feature gate so the
generated Rust table is available there as well. The C++ output is unchanged.
Tested: meson test -C build
Assisted-by: Codex <codex@openai.com>
hb_bit_page_t::add_range and del_range compute la = &elt(a) and
lb = &elt(b) and memset the span between them. When a and b map to
element indices out of order within the page (la > lb), the pointer
difference (char *) lb - (char *) la goes negative and wraps to a
huge size_t, so the memset writes past the page.
Only run the multi-element branch when la < lb, and otherwise leave
the page untouched. The single-element (la == lb) branch is already
memory-safe. This defends the page code itself in addition to the
inputCount cap on the depend path.
Extend the Arabic table and PUA generators to emit the data needed by
HarfRust's fallback shaper. Require explicit PUA input paths so regeneration
does not depend on the current working directory, and pass them from the
HarfBuzz update makefile.
The generated C table payload remains byte-for-byte unchanged; its invocation
comment now records the required inputs. The Rust output passes HarfRust's full
workspace tests, no-std check, formatting, and strict clippy; the full
HarfBuzz Meson suite also passes.
Assisted-by: Codex <codex@openai.com>
context_depend_recurse_lookups tracks covered sequence positions in
a fixed hb_bit_page_t, but the dependency-graph path never bounded
inputCount the way the shaping apply path does. A crafted GSUB
contextual rule with glyphCount past the page (e.g. 512) and a
SubstLookupRecord whose sequenceIndex lands in a higher page element
than endIndex makes hb_bit_page_t::add_range compute its memset
length as (char*)lb - (char*)la, which is negative and wraps to a
huge size_t, writing past the stack-allocated page. Reachable from
hb_subset_depend_from_face_or_fail on a crafted face.
Cap inputCount at HB_MAX_CONTEXT_LENGTH before the page is used,
matching the apply path; rules longer than that never apply during
shaping, so no real dependency edges are lost. Adds a regression
seed exercised by the depend fuzzer.
The subtables' transition functions are called once per transition
from the drive loop, but are big enough that the compiler declines to
inline them, leaving a call plus prologue in the hottest loop of AAT
shaping. Force them inline via HB_AAT_TRANSITION_INLINE, defined away
under HB_OPTIMIZE_SIZE.
Measured on the AAT corpus (clang -O3, instructions/cycles vs main):
Lucida Grande -10.3%/-5.2%, Menlo -6.6%, GeezaPro -5.6%/-4.4%,
Devanagari Sangam -5.6%/-2.2%. The ligature machine's transition alone
carries most of the Menlo/Lucida win. Code size: +16KB text (+0.65%).
Outputs byte-identical on the AAT corpus plus PingFang over a CJK
sample.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Make the float-to-double widening of the roundf() results explicit,
matching the treatment in glyf.hh from the previous round.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
When the requested direction differs from the script's horizontal
direction, the Graphite2 shaper reverses the buffer before segmenting.
Input cluster values then decrease along the buffer, so assigning each
Graphite group the cluster of its base character can leave earlier
characters outside the resulting cluster map.
Preserve the source span of every Graphite glyph while constructing the
output. At monotone cluster levels, seed each glyph from the minimum
endpoint of that span and use merge_clusters() over each Graphite output
range. Keep the historical base-character behavior at non-monotone
levels.
HarfBuzz cluster values are opaque client labels and can be repeated or
gapped. Merging them can therefore coalesce multiple Graphite layout
groups. Preserve the Graphite group index separately for positioning so
every group's advance is emitted even when its HarfBuzz cluster was
merged. Validate Graphite slot source bounds before indexing the input.
Add shape regressions using a subset of Awami Nastaliq and an API test
with repeated input clusters. The latter used to merge the output
clusters correctly but drop an entire layout-group advance, reducing
the total from 3200 to 1269.
Tested with:
meson test -C build test-graphite2
meson test -C build --suite shape
meson test -C build
Assisted-by: Codex <codex@openai.com>
Co-authored-by: Michael Brown <michael.brown@rubicotech.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Call sites feeding roundf/floorf/ceilf results into hb_clamp_to
promoted float to double implicitly, tripping -Wdouble-promotion under
clang. The overload widens explicitly — float cannot represent all
integer bounds exactly, so the clamp itself stays in double — and the
two glyf extents assignments that promote outside hb_clamp_to get
explicit casts. No behavior change.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
The lookup accelerator's digest is the union of its subtables'
digests, and apply_forward/apply_backward test it before applying the
lookup. For lookups with one subtable - the overwhelming majority -
the subtable's own digest is identical to the accelerator's, so the
per-subtable may_have retest in hb_applicable_t::apply is always true.
Dispatch single-subtable lookups straight to the apply function.
Invalid subtables do not collect and used to rely on their zeroed
entry's empty digest to gatekeep the null apply funcs; trim the zeroed
tail entries at accelerator create time instead, so the apply paths
never see them.
Benchmark-shape instruction counts: Roboto/en-thelittleprince -2.3%,
NotoNastaliqUrdu/fa-thelittleprince -3.7%; outputs unchanged.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Implement harfrust's new FontFuncs::populate_nominal_glyphs callback
(harfrust 0.13.1) with a single hb_font_get_nominal_glyphs call per
run, replacing one FFI round-trip per character during the
normalizer's short-circuit prefill. Speeds up the harfrust side of the
benchmark-shape parity suite by 6.2% on Menlo and 4.6% on
LucidaGrande; shaping outputs are unchanged.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
The buffer digest is only consumed by the OT lookup-apply loop. After
morx substitution it exists solely for a following GPOS pass; when
positioning goes through kerx/kern instead, rebuilding it is wasted
work. Speeds up the Menlo/en-thelittleprince benchmark by 2%; shaping
outputs are unchanged on the AAT benchmark fonts.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
move_to()'s two memmoves - the forward copy into out_info and the
rewind copy-back - were not charged against max_ops, while
shift_forward() already charges its moved tail. A morx insertion
subtable that keeps its mark far behind the insertion point can force
an O(distance) rewind plus re-copy per insertion action, for O(N^2)
total work that the max_ops budget never sees.
Charge count in both branches, mirroring shift_forward()'s failure
pattern. Charging only the rewind branch would also bound the
quadratic, but both memmoves are attacker-drivable work, and
symmetric accounting is simpler to reason about.
Fixes https://github.com/harfbuzz/harfbuzz/issues/6190
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>