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>
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
Reduce linear gradient anchors and normalize color lines before
printing them in test-paint. This makes the transcript reflect the
renderer-facing gradient geometry instead of backend-specific raw
COLRv1 anchors and stop ranges.
Also normalize signed zero in transform output so the fixtures stay
stable across backends.
Testing:
CCACHE_DISABLE=1 meson test -C build test-paint --print-errorlogs
Assisted-by: OpenAI Codex
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
The disabled assertions cover behavior from an older beyond-64k proposal.
That proposal has since changed, and current backends should not be
required to implement the stale loca-derived glyph count and metrics rules.
Keep the checks visible as disabled reminders until the library code is
adapted to the updated design.
Tested with:
CCACHE_DISABLE=1 HB_FONT_FUNCS=fontations meson test -C build test-be-glyph-advance test-be-num-glyphs
Assisted-by: OpenAI Codex
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
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
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
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
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.
* CMake: Fix building hb-gpu on Windows
Add the needed items for the program to build and link on Windows in the
CMake build files as well.
* CMake: Fix introspection builds with ICU
Grab the library name from the results of find_package(ICU COMPONENTS
uc) and use it instead for linking HarfBuzz, et al, so that we have a
proper command line to link to ICU-UC when running g-ir-scanner.
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>
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.
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
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>
In embedding projects, the global_allocator might already have been
overriden. There is no known way to keep the allocator library-local,
and allocator-bound containers are not a stable Rust feature yet.
Add an option to disable the allocator mapping to hb_malloc and friends,
so that an embedder can keep their own allocator.