Commit Graph
16361 Commits
Author SHA1 Message Date
Behdad Esfahbod 5b665b336b [matcher] Leave inlining decision on next/prev to compiler
Forcing this inline speeds up most benchmarks by a few percents,
but at least for the Duployan benchmark, it slows it down by 40%.
This is on Apple silicon.

I had noticed that HarfRust was performing faster on this benchmark,
and after lots of investigation, this force-inline seemed to be the
culprit.
2026-06-21 23:30:06 +01:00
Behdad Esfahbod 336958bd15 [GDEF] Slight speedup in mark-set lookup
Avoids the nonnullptr overhead. 1% speedup in Duployan benchmark.
2026-06-21 10:12:37 +01:00
Behdad Esfahbod 9e6929319b [rust] Use harfrust table-backed font API (#6036)
* [rust] Use harfrust table-backed font API

* [rust] Roll HR forward
2026-06-20 12:18:56 -06:00
Qunxin Liu ac0979b6f4 [subset] fix bug in math table
Don't keep constructions for glyphs that are only added during math closure,
since we don't do recursive closure over math table.
2026-06-18 16:13:24 -06:00
Qunxin Liu f2dd8dcb81 [subset] do math closure before gsub closure 2026-06-18 16:13:24 -06:00
Behdad Esfahbod ce1228bf5a [blob] Fix a pathological int overflow issue (#6034) 2026-06-17 02:04:23 -06:00
j0j1j2 72dfc30899 [hangul] Apply 'calt' feature to non-Hangul characters in Hangul runs (#6030) 2026-06-16 13:55:17 +02:00
Qunxin Liu 9c7f4dffe5 [subset-repack] add additional sorting after extension promotion (#6033)
assign_spaces() requires correct topological ordering to find space
roots, so add an additional topo sorting after extension promotion and
table splitting to keep thing sorted
2026-06-16 01:48:35 -06:00
Behdad Esfahbod e113622a98 Merge pull request #6028 from harfbuzz/sanitizer-fixes
Sanitizer fixes
2026-06-11 18:42:05 +02:00
Behdad Esfahbod ba4f5824ba [meson] Set CMake import libraries for Windows DLLs (#6027)
The Meson-generated CMake package described Windows shared-library
targets with IMPORTED_LOCATION pointing at the import library. CMake
expects DLL imported targets to put the runtime DLL in
IMPORTED_LOCATION and the import library in IMPORTED_IMPLIB.

Generate bindir-aware paths for Windows CMake packages and set both
target properties for all HarfBuzz imported targets. Static and
non-Windows shared builds keep their existing single-location behavior.

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

Testing:
meson setup build --reconfigure
meson compile -C build
meson test -C build
MinGW cross configure/build/install in /private/tmp
CMake consumer configure/build against harfbuzz::harfbuzz and harfbuzz::subset

Assisted-by: OpenAI Codex
2026-06-11 13:48:12 +02:00
Behdad Esfahbod 8565202817 [AAT] Size Lookup null object storage correctly
The AAT Lookup null object intentionally starts with format 0xFFFF so
lookup dispatch treats it as unsupported. However, its specialized null
storage was declared as only two bytes, while Null(Lookup<T>) is returned
as a Lookup<T> reference.

Declare enough storage for the current Lookup<T> object size so binding
the null reference is well-defined, while preserving the invalid format
bytes.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-11 10:27:07 +02:00
Behdad Esfahbod fa417b9a77 [CFF] Check numeric conversion to int
Malformed CFF dictionaries can contain real operands outside the
representable range of int. Avoid converting those values directly in
number_t::to_int(), and make arg_stack_t::pop_int() set the interpreter
error when the checked conversion fails.

Also make in_int_range() test the stored double value before converting,
so serialization-side range checks do not depend on an unchecked
conversion.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-11 10:22:09 +02:00
Behdad Esfahbod 32d8dc6fb9 [COLR] Sanitize composite mode before paint callbacks
COLR PaintComposite stores its composite mode as an untrusted table
byte, while the paint callbacks take hb_paint_composite_mode_t. Avoid
casting unsupported table values directly to the public enum. Map
unrecognized values to CLEAR, as required by the COLR table comment,
before calling push_group_for() and pop_group().

Also drop the duplicated COLR-side composite mode enum values and use
the public paint enum names for the accepted values.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-11 10:14:23 +02:00
Behdad Esfahbod 259cd49044 [build] Drop empty translation units (#6025)
GCC LTO can emit weak filename-derived placeholder symbols for empty
translation units, and those symbols can leak from shared libraries on
ELF builds.  The stricter check-symbols test added for weak symbols then
catches names such as hb_raster.cc.<hash>.

Remove the empty hb-raster.cc and hb-subset-cff2-to-cff1.cc units from
the build and tracked amalgamations.  Move the raster section docs to
hb-raster-image.cc, which remains part of the raster library.

Testing:
meson test -C build

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6021
Assisted-by: OpenAI Codex
2026-06-08 10:19:32 -06:00
Khaled Hosny b582759c0d [ot-layout] Fix docs typo
These function take a font not face as input.
2026-06-08 11:25:18 +03:00
Khaled Hosny 56feae4035 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
Behdad Esfahbod 719a1d3c10 [paint] Round COLRv1 alpha consistently
Round COLRv1 alpha values when packing them into 8-bit colors in the
native OpenType and FreeType paint paths.

This removes the old downward truncation bias and aligns native output
with the backend behavior expected by the updated paint fixtures.

Update the affected test-paint fixtures for the rounded alpha values.

Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex
2026-05-27 12:42:55 +02:00
Behdad Esfahbod 56ac9c925f [paint] Push COLRv1 root clip under font transform
Make the native COLRv1 paint paths report the root clip in font
units under the font transform. This matches the order used by
fontations and removes the need to pre-scale the HB-OT clip extents.

For the FreeType path, add a helper to convert FT_ClipBox values
back to font units before pushing them under the font transform, and
share that conversion with nested COLR glyph clip boxes.

Update paint and vector expectations for the new transform/clip stack.

Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex
2026-05-27 10:48:19 +02:00
Behdad Esfahbod c6ebdf6520 [font] Adjust extents rounding to be inclusive 2026-05-26 22:40:38 +02:00
Behdad Esfahbod b90b89feb9 [font] Fix extents scaling truncation 2026-05-26 22:35:31 +02:00
Behdad Esfahbod 98626f60ab [aat] Avoid overflow in obsolete offset math
Keep obsolete AAT offset-to-index helpers signed, but do the arithmetic
in 64-bit values before clamping back to an int index.  This preserves
the existing large positive failure index used for invalid offsets while
avoiding signed int overflow for malformed data.

Testing:
- b/util/hb-shape CharcoalCY.dfont Empty-handed
- b/util/hb-shape CharcoalCY.dfont --unicodes=002D,002D
- test/shape/run-tests.py build/util/hb-shape test/shape/data/in-house/tests/kern-format2.tests
- meson test -Cb

Assisted-by: OpenAI Codex
2026-05-26 18:56:46 +02:00
Behdad Esfahbod f9d86e2d73 [aat] Mark in-place deleted glyph replacements
Contextual and non-contextual AAT subtables replace glyphs in place.
When such a replacement produced the AAT deleted glyph, we changed only
the glyph ID and did not set the AAT-deleted metadata that later cleanup
uses to remove deleted glyphs from the buffer.

Make replace_glyph_inplace() match the other AAT replacement helpers by
setting the deleted scratch flag and glyph-info marker for glyph 0xFFFF.

Testing:
- b/util/hb-shape CharcoalCY.dfont --unicodes=002D,002D
- b/util/hb-shape CharcoalCY.dfont Empty-handed
- meson test -Cb

Assisted-by: OpenAI Codex
2026-05-26 18:47:19 +02:00
Behdad Esfahbod 20bc59869e [aat] Fix mort contextual substitution offsets
The legacy mort contextual subtable uses signed word offsets to
per-glyph substitution tables.  A zero offset means that there is no
table for that action.  We were treating the fields like morx lookup
indices with 0xFFFF as the sentinel, so zero-offset state entries tried
to substitute arbitrary glyphs from the start of the state table.

Keep morx using lookup-index semantics, but use signed offsets and the
zero sentinel for mort.  This fixes CharcoalCY shaping of text such as
"Empty-handed", which previously produced out-of-font glyph IDs.

Testing:
- b/util/hb-shape CharcoalCY.dfont Empty-handed
- b/util/hb-shape CharcoalCY.dfont --unicodes=002D,002D
- meson test -Cb

Fixes: https://github.com/harfbuzz/harfbuzz/issues/5887
Assisted-by: OpenAI Codex
2026-05-26 18:43:06 +02:00
Behdad Esfahbod 4b287d9f86 [rust] Remove accidental change to comments 2026-05-26 17:21:18 +02:00
Behdad Esfahbod 53c761783b [harfrust] Update shape glue for harfrust 0.8 (#6001)
Update the Rust bridge and Cargo dependency to harfrust 0.8.
Switch shaping calls to ShapeOptions, keep the cached shaper
path, and remove an unused face_data argument from the shaping
ABI.

Tested: meson compile -C build
Assisted-by: OpenAI Codex
2026-05-26 09:18:15 -06:00
Dominik Röttsches 0a7092643f [rust] Windows build fixes
Cast and add #[allow(clippy::unnecessary_cast)] as the C compiler
chooses different signedness for the hb_script_t and hb_tag_t enum
types depending on architecture. Add casts where needed and add
clippy suppressions to avoid warnings when compiled on systems
where the enum is unsigned by default.
2026-05-25 15:21:45 +03:00
Behdad Esfahbod f3c6b3ab92 [algs] Saturating arithmetic for get_size() on 32-bit (#5988)
On 32-bit platforms size_t is unsigned int, so the typical
get_size() computation `min_size + count * static_size`
silently wraps when the product exceeds UINT_MAX.  The
truncated value then flows into sanitize / serialize as a
small but plausible size, defeating bounds checks.

Add three helpers in hb-algs.hh:

  hb_unsigned_mul_saturate (a, b, ...)
  hb_unsigned_add_saturate (a, b, ...)
  hb_unsigned_mul_add_saturate (a, b, c)   /* a*b + c */

They saturate to SIZE_MAX on overflow.  Variadic overloads
left-fold so 3+ arguments work.  On 64-bit (size_t wider than
unsigned int), all three reduce to plain a*b / a+b — the
inputs to size computations are at most unsigned int so the
result fits in size_t without overflow.

Convert every get_size() that does arithmetic over variable
inputs:

  hb-open-type.hh        UnsizedArrayOf, ArrayOf,
                         HeadlessArrayOf, ArrayOfM1,
                         sorted-array-with-header, CFFIndex
  hb-ot-layout-common.hh CmapSubtableFormat-style,
                         VarRegionList, VarData, MultiVarData,
                         DeltaSetIndexMapFormat01
  hb-ot-hdmx-table.hh    DeviceRecord, hdmx
  hb-ot-cff-common.hh    Charset0, Charset wrapper
  hb-ot-cff1-table.hh    Encoding, Charset wrapper
                         (also widened unsigned accumulator
                         to size_t)
  hb-ot-os2-table.hh     OS/2 (widened accumulator to size_t)
  hb-ot-var-common.hh    TupleVariationHeader,
                         TupleVariationData accumulator
  hb-ot-var-hvar-table.hh DeltaSetIndexMap
  hb-vector.hh           hb_vector_t::get_size

When saturation kicks in, check_range() and extend_size()
naturally reject the resulting value (SIZE_MAX truncated to
unsigned is UINT_MAX, far past any real blob; extend_size
already rejects sizes >= INT_MAX).

Assisted-by: Claude <noreply@anthropic.com>
2026-05-18 15:11:34 -06:00
Dominik Röttsches 4321818220 Cross-platform clippy-friendly casts in FFI
Bindgen generates a std::os::raw::c_char as return type for
functions like hb_blob_get_data. Depending on platform/arch, this
can be an i8 or u8. In the Rust side code, receiving
the data, these are interpreted as u8. Perform the pointer
casts in a way that compiles without clippy warnings about
unnecessary casts when the c_char type was already u8.
2026-05-18 17:02:39 +03:00
Khaled Hosny 8d24ed6cd6 [arabic-pua] Fix mapping for isolated lam alef maksura ligature (#5985)
Correct the ArabicPUATraditional.txt entry for 0xF295 which should be
isolated not final form. Also enable 0xFC43 ligature so the ligature is
actually used.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5984
2026-05-17 15:24:40 -06:00
Behdad Esfahbod c31d554e4a Some more 32bit overflow hardening
Should fix https://issues.chromium.org/issues/513143921
plus speculative fixes.
2026-05-17 14:24:10 +01:00
Behdad Esfahbod 56b9727aa7 [check-symbols] Err on weakly-public symbols as well
https://github.com/harfbuzz/harfbuzz/issues/5895#issuecomment-4461712887
2026-05-16 13:17:31 +01:00
Behdad Esfahbod cf9c3eb36e [vector] Fix heap buffer overflow in append_base64 / append_len
When the sum old_len + out_len (or old_len + l) exceeded INT_MAX,
the (int) cast turned it negative.  resize_full() treated negative
size as zero, alloc(0) succeeded, and the subsequent write loop
overflowed the buffer.

Fix both layers:

- resize_full(): reject negative size_ (return false) instead of
  silently treating it as zero.  This is defense-in-depth for every
  caller that casts unsigned to int.

- append_len() and append_base64(): use hb_unsigned_add_overflows()
  to detect unsigned wraparound before the cast.  This catches the
  case where old_len + new_bytes > UINT_MAX wraps to a small
  positive value that would pass the negative check.

Assisted-by: Claude <noreply@anthropic.com>
2026-05-16 13:06:40 +01:00