Commit Graph
22239 Commits
Author SHA1 Message Date
Behdad Esfahbod 491516cab8 [subset] Reject condition pinning with subnormal region scalars
A pinned float region product can be nonzero but subnormal. Multiplying
by a retained axis may then round it to zero, while positive rescaling
of the residual condition removes that threshold and selects a different
substitution after partial instancing.

Detect these source regions and reject affected variable conditions
instead of emitting a false activation. Keep full instancing and ordinary
fractional partial instancing working. Avoid scanning region axes when
their count cannot produce a subnormal product, and handle set OOM.

Add a valid 20-axis fixture and API regression. The partial request
incorrectly succeeds before the fix; controls check source/full output
and an ordinary partial request. The full Meson suite passes: 272 tests,
one skip, no failures.

Assisted-by: OpenAI Codex
2026-10-22 07:08:59 -06:00
Chad Brokaw 01a2fc3e5d [rust] Move the Fontations font functions to read-fonts 0.46 and ScalerFont (#6437)
Updates read-fonts to 0.46 and skrifa to 0.49, and drops skrifa's older
collections: outlines draw through a ScalerFont, and bitmaps, color glyphs,
palettes and ink extents come from the read-fonts font model. Skrifa is now
only needed for drawing.

Outlines are drawn unhinted at the units per em, which keeps fractional
points as before. Bitmaps are still chosen by the font's ppem. Other ink
extents come from the model, in COLR, VARC, glyf, CFF2, CFF order, so VARC
glyphs and COLRv1 clip boxes now measure as they do with the ot font
functions.
2026-10-22 06:51:49 -06:00
Chad Brokaw d15141a18a [rust] Update HarfRust to 0.15 (#6438) 2026-10-22 06:48:01 -06:00
Behdad Esfahbod 3272df037c [subset] Allow CFF2 VariationStores larger than 65535 bytes (#6432)
OFF 2026 section 5.3.3.11.2 permits larger ItemVariationStores and
specifies a saturated length field of 65535. Partial CFF2 instancing
currently rejects these stores while serializing them.

Saturate the field while retaining the 32-bit offset size check.
Add a font with 200 referenced regions over 60 axes and exercise
partial instancing and extents at three locations. The test fails
before the fix because the output loses its CFF2 table.

Validation: full Meson suite, 272 passed and one skipped.

Assisted-by: OpenAI Codex
2026-10-21 19:59:08 -06:00
Behdad Esfahbod 2b6ffde1e5 [cff] Discard ignored Private DICT blend operands while loading CFF2 (#6431)
The ordinary CFF2 Private DICT parser ignores hint blend operators but
leaves their raw operands on its stack. Multiple valid blend groups can
therefore overflow the stack during font loading, making glyph extents
and drawing fail. The subset parser already discards these operands.

Clear ignored operands after each hint blend in the ordinary parser too.
Add a synthetic font with two seven-result groups over 40 regions and
check its glyph extents at default and non-default locations. Each group
fits the stack, but their raw operands together exceed its capacity.

The regression fails before the fix and passes after. The complete
Meson suite passes: 272 tests passed, one skipped.

Assisted-by: Codex <noreply@openai.com>
2026-10-21 19:58:41 -06:00
Behdad Esfahbod 5a1c0c4660 [aat] Keep deleted glyphs in the buffer glyph set (#6433)
Ligature substitutions replace consumed components with DELETED_GLYPH.
The deletion helper did not add that sentinel to the cached buffer glyph
set, so a later state machine triggered by the deleted-glyph class could
be skipped when the buffer started with at least four glyphs.

Record DELETED_GLYPH in the active set, as the other replacement helpers
do. Add a synthetic morx font that ligates glyphs 1,2 into 3, then uses a
deleted-glyph transition to enable substitution 4 -> 5. Cover both the
three-glyph scan and the four-glyph cached-set paths.

Found while reviewing harfbuzz/harfrust#542.

Validation: all 292 Meson test groups pass, including the shaping suite.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-10-21 19:42:13 -06:00
Behdad Esfahbod cb56bae961 [subset] Zero CFF2 instance bounds when no glyph contributes extents (#6430)
Instancing a CFF2 font with only empty outlines leaves the head bounds
accumulator at its inverted initialization sentinels. These are then
serialized as xMin=yMin=32767 and xMax=yMax=-32767.

Reset an empty accumulator to zero after collecting CFF2 extents. This
also provides a valid FontBBox if the instance is downgraded to CFF1.

Add a reproducible synthetic font and an API regression that fails before
the fix. The regression also checks preservation of the empty glyph's
advance and bearing. The complete Meson suite passes: 272 tests passed,
one skipped.

Assisted-by: Codex <noreply@openai.com>
2026-10-21 18:13:19 -06:00
Behdad Esfahbod 0a43a9dd4b [ot-tag] Constant-initialize language lookup caches (#6429)
In C++11 builds, copy-initialization of hb_atomic_t from zero can call
the non-constexpr move constructor and emit a runtime static guard.
HarfBuzz disables thread-safe statics, so concurrent first use races
on that guard before reaching the atomic cache operations.

Direct-initialize all three language caches through the constexpr
scalar constructor. Clang 18 then emits no initialization guards.

Reproduced the shape_threads TSan race on unmodified main using Clang
18 and C++11. With this fix, the full TSan suite passes: 289 passed,
three skipped. The existing shape_threads regression passes too.

Assisted-by: OpenAI Codex
2026-10-21 16:34:19 -06:00
jfkthame 3f9ee71433 [arabic] Store glyph advances during STCH calculation pass. (#6426)
This avoids the need to call get_glyph_h_advance again in the second pass.
2026-10-21 11:13:54 -06:00
Behdad Esfahbod 144235cf10 [instancer] Switch delta calculations back to floats (#6424)
The scalar cache stores floats, so computing uncached tuple scalars and
instancer deltas as doubles made results depend on whether the cache was
used. Restore single-precision calculations throughout the instancer and
update the affected CFF2 partial-instancing fixtures.

The current glyf partial-instancing comparison still matches fontTools,
so it does not need a new no_fonttools opt-out.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6423
Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-20 18:13:50 -06:00
Behdad Esfahbod a69b43c1fd [ot] Cache variation scalars as floats (#6417)
* [atomic] Use C++11 atomics throughout

Remove the compiler-intrinsic, user-provided, and HB_NO_MT atomic
implementations in favor of the existing std::atomic implementation.
This also allows hb_atomic_t to store floating-point values.

Use direct initialization and a non-constexpr move constructor so the
implementation builds with C++11 on GCC and Clang.

Checked GCC and Clang C++11, HB_NO_MT, HB_TINY, and 32/64-bit MinGW
compilation. The core library also builds without linking libstdc++.
Full test coverage will run in CI.

Assisted-by: OpenAI Codex

* [ot] Cache variation scalars as floats

The scalar cache rounds floats to scaled integers, losing precision for
small values. A variation result can therefore change between its first
calculation and a later cache hit.

Store floats directly in hb_atomic_t and use NaN for empty entries.
Remove the integer conversion and the zero fast path it required.

Add exact round-trip and clear tests for scratch and heap caches,
including a small scalar produced by three variation axes. The test
fails with integer storage and passes with float storage. The core
library builds without a C++ standard-library dependency.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6416
Assisted-by: OpenAI Codex

* [atomic] Preserve the HB_NO_MT implementation

Keep plain storage and operations when thread safety is disabled,
including HB_TINY, to avoid atomic reference-counting overhead.
Implement these operations directly without restoring the compiler
intrinsics or user-provided atomic hooks.

Checked GCC and Clang C++11 compilation and execution, including the
scalar-cache precision regression under HB_NO_MT, and the HB_TINY
atomic smoke test.

Assisted-by: OpenAI Codex
2026-10-20 13:43:26 -06:00
nussaibah shaikh 6145d99262 Free the text copy on every hb_shape_justify() return path (#6422)
hb_shape_justify() copies the buffer text so it can reshape while
solving for the axis value, but only the solver path at the end
frees the copy. The three "nothing to solve" success returns
(default advance already in range, maximum expansion still short of
the target, maximum shrink still above it) and the three shaping
failure returns leak it, so ordinary line justification leaks one
text copy per call.

Free it with a scope guard right after the allocation, as the rest
of the tree does, and drop the explicit free at the end.

Reproduced with leaks --atExit on a plain experimental-API build:
four calls on Estedad-VF.ttf give four ROOT LEAKs at hb-shape.cc:319,
none with the fix. Add test-shape-justify.c covering all five paths
under the experimental-API test list so the asan-ubsan job runs it
under LeakSanitizer. The full ASan+UBSan Meson suite passes
(289 ok, 2 skipped).

Assisted-by: Claude
2026-10-20 11:25:59 -06:00
Behdad EsfahbodandOpenAI Codex 22e7463b59 [GPOS] Keep anchor variation adjustments fractional (#6421)
AnchorFormat3 returned each scaled variation delta as an integer before
subtracting the mark and base anchors. Rounding the two deltas separately
can shift the final attachment by an output unit even with an exact
quarter scalar.

Add float-preserving device queries for anchor resolution. Keep hinting
adjustments and ValueRecord queries on the existing integer path, and
retain the final anchor-difference rounding.

Add ten cases with exact scalars, signed deltas, negative and independent
axis scales. Six fail against the original implementation. The full
meson test suite passes (272 passed, one skipped), as does a reduced
HB_NO_VAR/HB_NO_HINTING compile.

Fixes: #6420

Co-authored-by: OpenAI Codex <noreply@openai.com>
2026-10-19 21:59:14 -06:00
Behdad Esfahbod b98ffb1fbd [cache] Reject out-of-range keys on reads (#6419)
* [cache] Reject out-of-range keys on reads

An empty entry can match an out-of-range key when the packed cache
entry leaves storage bits unused. In the 256-entry binary coverage
cache this reports glyph IDs 32512-32767 as NOT_COVERED, skipping
Context/ChainContext format 2 substitutions and positioning.

Apply the same key range check in get() as set(). Add regression
coverage for spare-bit and full-width entries across all three
storage sizes, with and without atomics.

The new cache test fails before the fix and passes afterward, also
with HB_TINY. All 28 GSUB/GPOS Context/ChainContext boundary cases
pass. meson test -C build: 272 passed, 1 skipped, 0 failed.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6418
Assisted-by: OpenAI Codex

* [cache] Combine cache miss checks into one branch

Fold the key range check into the existing miss condition using
bitwise operations. XOR the stored and queried tags so their
mismatch can be combined directly with key overflow and the empty
entry check.

Use a scalar empty-entry constant rather than casting through
item_t, which creates temporary atomic objects in GCC builds.
The binary, mapping, and cmap lookup probes now each have one
conditional branch with GCC 15 and Clang 21 at -O2 on x86-64,
compared with two or three in the initial fix.

Testing: meson test -C build: 272 passed, 1 skipped, 0 failed.
All 28 GSUB/GPOS Context/ChainContext boundary cases pass. The cache
regression also passes with Clang and with HB_TINY.

Assisted-by: OpenAI Codex
2026-10-19 19:16:51 -06:00
Behdad Esfahbod 8c59a6d47a Merge pull request #6414 from harfbuzz/wasm-host-glue-fixes
[wasm] Harden host import glue against invalid guest pointers
2026-10-19 15:53:56 -06:00
Behdad EsfahbodandClaude Opus 5.5 e34ce9eab0 [wasm] Don't dereference null return pointer in HB_RETURN_STRUCT
If retptr failed validation, _name_ptr stayed null and the macro went
on to bind a reference to *nullptr, which a function body would then
write through.  Return early whenever the pointer is null.

The macro currently has no users; checked that a sample use compiles.
meson test passes on a -Dwasm=enabled build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:40:59 -06:00
Behdad EsfahbodandClaude Opus 5.5 b3b84fa571 [wasm] Fix contours allocation check in font_copy_glyph_outline
The check meant to catch a failed contours allocation tested
!n_contours instead of n_contours.  An allocation failure went
unnoticed, leaving the guest with n_contours > 0 and a null contours
array; the check was otherwise unreachable on success since points
are always accompanied by contours.

Tested: meson test passes on a -Dwasm=enabled build; a wasm module
copying a glyph outline through the allocating path still succeeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:40:59 -06:00
Behdad EsfahbodandClaude Opus 5.5 f428eaef29 [wasm] Release blob reference in face_create
hb_face_create() takes its own reference on the blob, so the one
returned by hb_blob_create() was never released.

Tested: meson test passes on a -Dwasm=enabled build; a wasm module
calling face_create on a valid blob shapes fine under valgrind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:40:59 -06:00
Behdad EsfahbodandClaude Opus 5.5 a71aa86c2b [wasm] Don't pass unvalidated guest pointers to host functions
buffer_set_contents, face_create, and font_set_coords converted guest
array addresses to native pointers, using nullptr when validation
failed, but then handed the result to hb_memcpy(), hb_blob_create(),
and hb_font_set_var_coords_normalized() unconditionally.  A font wasm
module passing an out-of-range address with a nonzero length made the
host copy from NULL.  face_create also dereferenced the blob_t
parameter without checking it.

Fail the call when validation fails.  buffer_set_contents now
validates before resizing the buffer.

Tested with the reporter's PoC fonts: each now traps in the guest with
"out of bounds memory access" instead of faulting in the host.
meson test passes on a -Dwasm=enabled build.

Reported-by: Ostrolab security team

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:40:59 -06:00
Behdad EsfahbodandClaude Opus 5.5 5e821de825 [wasm] Validate font_glyph_to_string output buffer
font_glyph_to_string was registered with the WAMR signature "(ii$*)"
while the C function takes (font, glyph, char *s, uint32_t size).
WAMR thus treated the guest's size argument as a pointer and passed
the low 32 bits of its native address as size, defeating the length
bound in hb_font_glyph_to_string().  A font-supplied wasm module could
make the host write a glyph name past the end of the module's linear
memory.

Merely fixing the signature to "(ii*~)" is not enough: when WAMR is
built with hardware bounds checking (the x86-64 Linux default), its
native-call glue skips the size check for '*~' and relies on guard
pages, so an oversized range still faults inside host code.

Take the buffer as a plain guest offset instead and validate the whole
[s, s + size) range with HB_ARRAY_PARAM, which goes through
wasm_runtime_validate_app_addr().  The guest-side ABI is unchanged.

Tested with the reporter's PoC fonts: size now arrives as 144, and a
variant passing size=0x7FFFFFF0 traps with "out of bounds memory
access" before reaching hb_font_glyph_to_string().  meson test passes
on a -Dwasm=enabled build.

Reported-by: Ostrolab security team

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:40:59 -06:00
Behdad EsfahbodandMar e0f6fbfadc [subset] Sanitize substitute feature parameters (#6413)
* [layout] Sanitize substitute feature params with their feature tag

FeatureTableSubstitutionRecord sanitized its substitute Feature with
no feature tag, so FeatureParams::sanitize() checked nothing for it.
The subsetter reads those params by the tag of the feature they
replace: Record::subset() when instancing applies the substitutes,
and FeatureTableSubstitutionRecord::subset(),
FeatureVariations::collect_name_ids() and
_features_have_equal_params() since #6349 and #6350.  A size, ssXX
or cvXX substitute could thus be read past the end of the table.

Pass the FeatureList down from GSUBGPOS::sanitize() and sanitize
each substitute with the tag of its featureIndex, the tag every
reader uses.

Test: test_feature_substitution_params_sanitize in test-serialize.

Assisted-by: Claude

* [subset] Drop feature params when built without them

With HB_NO_LAYOUT_FEATURE_PARAMS, FeatureParams::sanitize() checks
nothing and collect_name_ids() keeps none of their names, yet
FeatureParams::subset() still copied the params by their tag.
Return false there too, so the subsetter drops them, like the other
FeatureParams readers do in that configuration.

Assisted-by: Claude

---------

Co-authored-by: Mar <mardgez13@gmail.com>
2026-10-19 15:39:12 -06:00
Mar a1d34fedce [subset] Drop feature params when built without them
With HB_NO_LAYOUT_FEATURE_PARAMS, FeatureParams::sanitize() checks
nothing and collect_name_ids() keeps none of their names, yet
FeatureParams::subset() still copied the params by their tag.
Return false there too, so the subsetter drops them, like the other
FeatureParams readers do in that configuration.

Assisted-by: Claude
2026-10-19 12:04:29 -06:00
Mar 4a60bf8333 [layout] Sanitize substitute feature params with their feature tag
FeatureTableSubstitutionRecord sanitized its substitute Feature with
no feature tag, so FeatureParams::sanitize() checked nothing for it.
The subsetter reads those params by the tag of the feature they
replace: Record::subset() when instancing applies the substitutes,
and FeatureTableSubstitutionRecord::subset(),
FeatureVariations::collect_name_ids() and
_features_have_equal_params() since #6349 and #6350.  A size, ssXX
or cvXX substitute could thus be read past the end of the table.

Pass the FeatureList down from GSUBGPOS::sanitize() and sanitize
each substitute with the tag of its featureIndex, the tag every
reader uses.

Test: test_feature_substitution_params_sanitize in test-serialize.

Assisted-by: Claude
2026-10-19 12:04:29 -06:00
dependabot[bot] 143c483079 Bump ossf/scorecard-action from 2.4.4 to 2.5.0
Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.4 to 2.5.0.
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](https://github.com/ossf/scorecard-action/compare/2d1146689b8cda280b9bc96326124645441f03bc...fa7117db83c52d787ae5a89f350999701505d78e)

---
updated-dependencies:
- dependency-name: ossf/scorecard-action
  dependency-version: 2.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-19 14:18:07 +03:00
dependabot[bot] ffb1340109 Bump github/codeql-action/upload-sarif from 4.38.3 to 4.39.0
Bumps [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) from 4.38.3 to 4.39.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/24c54180a607b1449ed407dd24f251e4e9147c8d...6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee)

---
updated-dependencies:
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.39.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-19 14:17:39 +03:00
Behdad Esfahbod 0bfc7a9b16 [glyf] Charge composite offsets to the work budget (#6410)
* [glyf] Charge composite offsets to the work budget

Composite glyphs prepare component offsets before descending into
children. This work was not charged to the shared rendering budget,
including offsets for children later skipped by cycle detection.
Repeated preparation through COLR extents could time out the shaper.

Charge each offset before loading it and restore the scratch length
on failure. Add a cyclic-composite budget regression and the minimized
fuzzer testcase.

The full Meson suite passes (292 passed, one skipped). The reproducer
completes under ASan/UBSan in 17 seconds instead of timing out after
60 seconds. A failing-allocation variant passes 100 runs.

Fixes: https://oss-fuzz.com/testcase-detail/6193853460447232
Assisted-by: OpenAI Codex

* [glyf] Charge component preparation as traversal work

Component preparation parses records and updates scratch vectors, but
charging one unit per record still allows excessive work within the
shared budget. Use the existing 16-unit glyph traversal charge for
preparing a component, including children skipped by cycle detection.

Increase the cyclic-composite regression's budget so it also catches
the undercharged preparation path. The reproducer now takes about
1.1 seconds under ASan/UBSan and 0.03 seconds in the normal build.

Tested with the full Meson suite (292 passed, one skipped), 100
sanitizer reproducer runs, and 100 failing-allocation variant runs.

Assisted-by: OpenAI Codex
2026-10-18 19:54:45 -06:00
Behdad Esfahbod 8abfd0d16e [subset] Reject failed glyph sets before allocating flat maps (#6409)
An allocation failure can leave out-of-range glyph IDs in the GSUB
set because subsequent range deletions are skipped. Building the flat
glyph map from that set can then request several gigabytes before the
set's error state is checked.

Reject an errored GSUB glyph set before sizing the flat map, and add
the minimized fuzzer testcase to the regression corpus.

Tested with the full Meson suite (292 passed, one skipped) and 100
reproducer runs under ASan/UBSan with failing allocations enabled.

Fixes: https://oss-fuzz.com/testcase-detail/5574495277219840
Assisted-by: OpenAI Codex
2026-10-18 18:01:11 -06:00
Behdad Esfahbod 54d71be605 [subset] Clamp overflowing COLRv1 variation values (#6408)
Unbounded variation deltas can overflow integer conversions while
instancing COLRv1 paints and clip boxes. Clamp coordinates, radii,
affine coefficients, and fixed-point values before narrowing them.
Keep affine base precision and existing alpha and clip rounding.

Add a generated font and regression checks for positive and negative
overflow in full and composed instances. Parenthesize the fixed-point
roundf argument so its template comma is safe for macro expansion.

Validation: meson compile -C build and meson test -C build pass
(292 tests passed, one skipped). The font regenerates identically.

Assisted-by: OpenAI Codex
2026-10-18 15:26:44 -06:00
Behdad Esfahbod ac906f7f6b [set] Avoid MSVC unsigned-negation warnings (#6407)
Use the complement of ELT_MASK to align bitset and coverage cursors.
This preserves the masks while avoiding C4146 from negating the
unsigned ELT_BITS constant.

Validation: the build and full test suite pass in build-default
(290 tests). The usual build is blocked by unrelated local
HarfRust/Fontations compatibility errors. MSVC was unavailable.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6406
Assisted-by: OpenAI Codex
2026-10-18 14:58:48 -06:00
Roshan Ramani bb702ff6de [docs] Fix five function names in the user manual
The manual named hb_ot_color_reference_png/svg(),
hb_font_paint_or_fail_glyph(), hb_ft_get_face() and
hb_coretext_face_get_ct_font(), none of which exist. Use
hb_ot_color_glyph_reference_png/svg(), hb_font_paint_glyph_or_fail(),
hb_ft_font_get_face() and hb_coretext_font_get_ct_font().

Assisted-by: Claude Code:claude-opus-5-5
2026-10-17 14:13:49 +03:00
nussaibah shaikh 47b18b6ebd [font] Don't read stale design coords in hb_font_set_variation() (#6402)
hb_font_set_variation() seeds its new design coords from the font's
existing ones for every axis of the current face, trusting an assert
that their lengths match. hb_font_set_face() keeps the font's
variation coords, which stay sized for the old face, so switching to
a face with more axes and then calling hb_font_set_variation() reads
past the old array: a heap-buffer-overflow read with NDEBUG, an
assertion failure otherwise.

Only reuse the existing design coords when their length matches the
current face; otherwise start from the defaults, as when none are set.

Reproduced the overflow under ASan with NDEBUG and the assertion
failure in the default build. Added a regression test in test-font.c
that fails without the fix. The full ASan+UBSan Meson suite passes.

Assisted-by: Claude
2026-10-16 12:18:00 -06:00
Behdad Esfahbod cb651c51d9 [ot] Ignore variation deltas at the default instance (#6401)
Use has_nonzero_coords when creating a shaping plan, and treat explicit
all-zero coordinates as an empty location in ItemVarStoreInstancer.
A constant GDEF delta then cannot change a condition at the default
instance, matching OFF section 7.1 and the condition's default field.

Keep the Boolean result in the stored int16 default when partial
instancing moves an oversized condition value into a private bias row.
Only the excess belongs in that row, since default instances ignore it.

Add a regression for empty versus explicit default plan keys and shaping
across default, varied, and default locations. Existing subset precision
tests cover the private bias and repeated instancing.

Validation: all 290 Meson test groups pass with experimental APIs enabled.

Assisted-by: Codex
2026-10-16 11:01:47 -06:00
Mar 5365d272d5 [font] Deprecate hb_font_set_face()
Changing the face now resets font funcs. Deprecate the setter in favor
of creating a new font with hb_font_create() and setting its properties.
Keep the exported symbol and move its declaration to hb-deprecated.h.

Document the deprecation in NEWS and the API section index. Guard the
face-setter tests with HB_DISABLE_DEPRECATED, and suppress expected
warnings from their deliberate use of the deprecated API.

The full ASan Meson suite passes (270 passed, 1 skipped). test-font also
builds and passes with HB_DISABLE_DEPRECATED. Its source passes Clang
-Werror checks both with and without deprecated APIs enabled.

Assisted-by: Claude
Assisted-by: Codex
2026-10-16 00:19:21 +03:00
Mar ef64f7ea8b [font] Reset font funcs in hb_font_set_face()
Font funcs and their data may hold pointers into the font's face.
hb_font_set_face() released the old face but kept those funcs, causing
stale lookups or a use-after-free when the last face reference was gone.

Release the font funcs and their data while the old face is still alive,
then install the default funcs for the new face. Preserve the other font
properties and document the callback reset in the API docs and NEWS.

Add regressions for OpenType lookups and custom font-data destruction.
Reproduced stale glyph lookup and the heap-use-after-free under ASan
before the fix. The full ASan Meson suite passes (270 passed, 1 skipped),
and the two regressions also pass with HB_FONT_FUNCS=ft.

Assisted-by: Claude
Assisted-by: Codex
2026-10-16 00:19:21 +03:00
Behdad Esfahbod 6cb629b389 Merge pull request #6400 from harfbuzz/codex/ot-layout-size-followup
[subset] Share GPOS subsetting across table widths
2026-10-15 14:52:57 -06:00
Behdad Esfahbod 7aa4508c7c [subset] Share retained mark attachment row selection
Use the same count-bounded coverage, class-map filtering, non-null
anchor test, and row-major index selection for MarkBase and MarkMark.
Pass a read-only 16/24-bit offset view after decoding the matrix rows.
Keep typed anchor serialization and the existing vector error behavior.

Saves 5120 bytes at -O3 and 3160 bytes at -Os with GCC 15.3 without
LTO, and 5912 bytes with Clang 21 LTO. The full Meson suites pass with
beyond-64k enabled and disabled; 288 synthetic subset cases match
baseline table bytes, plus 144 cases in the no64 build.

Sampled subset CPU-time geometric means change by +0.82% for ordinary
fonts and -0.55% for variable fonts. The largest ordinary-font change
is +3.42% for Noto Sans Devanagari.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 14:49:13 -06:00
Behdad Esfahbod a140b5dc1e [subset] Share PairSet value traversal across glyph widths
Expose the source glyphs, values, count, stride, and device-offset
base through a native view. Share effective-format analysis and
variation-index collection without changing typed glyph emission.
Move the value-copy context out of the source-width template too.

Retain the outer scan guard for variable-device instancing and the
existing record-serialization error behavior.

Saves 1576 bytes at -O3 and 128 bytes at -Os with GCC 15.3 without
LTO. The full Meson suite passes and 288 synthetic narrow/wide subset
cases match baseline table bytes. Sampled CPU-time geometric means
change by -1.08% with hint stripping and -0.23% for font instancing.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 14:45:30 -06:00
Behdad Esfahbod 01e3e76ac8 [subset] Share mark attachment variation-index traversal
Use read-only 16/24-bit offset views to share mark-anchor and
ligature-matrix traversal. Keep count-limited coverage iteration,
row-major index selection, original anchor bases, and null offsets.
The typed wrappers retain table sanitization and field decoding.

Saves 5752 bytes at -O3 and 3272 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full Meson suite passes. Synthetic
16/24-bit subset checks match baseline table bytes in 192 cases,
including variation devices, null matrices, class pruning, and
retain-GID modes. Sampled variable-font subset CPU time changes by
+0.57% overall, with individual cases from +0.24% to +0.79%.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 14:39:33 -06:00
Behdad Esfahbod 72dd0b0d96 [subset] Share PairPos class-matrix subsetting across widths
Resolve the source base, value formats, and matrix dimensions before
analyzing and copying class-pair values. Keep those operations in a
common native view instead of duplicating them in the small and
beyond-64k table instantiations.

Preserve the variable-device scan guard and propagate allocation
failure when collecting retained second-class indices.

Saves 2864 bytes at -O3 and 1336 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full Meson suite passes. Sampled subset
CPU-time geometric means change by -0.56% for ordinary fonts and
-1.55% for variable fonts.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 14:23:51 -06:00
Behdad Esfahbod ca4f037495 [subset] Share mark-to-ligature coverage serializers across widths
The coverage iterator needs glyph IDs and the mark-record count, but
zipping in the records gives it a type that depends on the source
width. Zip with a bounded index range instead, retaining the same
truncation when coverage and record counts differ.

Saves 7552 bytes at -O3 and 2112 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full Meson suite passes; sampled subset
CPU-time changes range from -0.18% to +0.83%.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 14:19:55 -06:00
Behdad Esfahbod fda2374fd0 [ot] Reduce duplicated layout code for beyond-64k tables (#6399)
* [ot] Share mark attachment positioning across table widths

MarkArray::apply instantiates the same positioning and attachment-chain
updates for each mark-array and anchor-matrix representation.

Resolve the format-specific anchors in the wrapper and pass them to a
common helper. Preserve the anchor checks, buffer flags, messages, and
attachment overflow behavior.

With GCC 15.3 on x86-64 without LTO, this removes 1576 bytes of core
code/read-only data at -O3 and 648 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and sampled shaping benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>

* [ot] Share cursive attachment positioning across table widths

CursivePosFormat1_2 duplicates the direction-dependent positioning and
attachment-chain updates for legacy and beyond-64k entry/exit records.

Keep record access and anchor validation in the format-specific wrapper,
then pass the resolved anchors to a common attachment helper. Preserve
all direction cases, chain reversal, overflow handling, and messages.

With GCC 15.3 on x86-64 without LTO, this removes another 2760 bytes of
core code/read-only data at -O3 and 864 bytes at -Os. Validated with the
full Meson suite (292 passed, one skipped) and sampled shaping benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>

* [subset] Share mark-class remapping across record widths

Mark classes remain 16-bit values in both mark-record representations;
only the record stride and array count differ. Decode those in the
wrapper and share the class collection and remapping work.

Give the common helper hidden inline linkage so its body is shared
across translation units as well as record formats. Class ordering,
existing mappings, and allocation behavior are preserved.

With GCC 15.3 on x86-64 without LTO, this removes 1152 bytes of subset
code/read-only data at -O3 and 1440 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>

* [subset] Share SinglePos serializers across source formats

SinglePos output serializers only need the source value format and
ValueBase pointer, but carried the full source lookup type through
several template layers. The per-glyph mapper also had distinct lambda
types for legacy and beyond-64k source tables.

Pass the source format and base directly, and use a common mapper with
the same reference captures as the original lambda. Output formats,
device offsets, value copying, and allocation behavior are preserved.

With GCC 15.3 on x86-64 without LTO, this removes 18080 bytes of subset
code/read-only data at -O3 and 9472 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>

* [subset] Share delta substitution subset serialization

SingleSubstFormat1_3 constructs equivalent remapping iterators in each
source-format specialization, giving the output and coverage serializers
distinct iterator types and duplicating their bodies.

Move the subset preparation into a common helper taking the decoded
coverage, delta, and glyph mask. Preserve the glyph intersection,
modular delta calculation, remapping, and serializer failure behavior.

With GCC 15.3 on x86-64 without LTO, this removes 11896 bytes of subset
code/read-only data at -O3 and 5776 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>

* [ot] Share SinglePos optical-bound context setup

SinglePos position_single duplicates the temporary apply context and
value application for each source representation. Keep coverage and
value-index checks in the wrappers and share the context setup through
ValueFormat, passing the original value base explicitly.

With GCC 15.3 on x86-64 without LTO, this removes 2088 bytes of core
code/read-only data at -O3 and 616 bytes at -Os. Optical-bound benchmarks
show no consistent slowdown across the four source formats.

Validated with the full Meson suite (292 passed, one skipped) and
synthetic optical-bound checks for all directions, 16/24-bit glyph IDs,
missing glyphs, and device adjustments.

Assisted-by: OpenAI Codex <codex@openai.com>

* [subset] Share retained mark-anchor index collection

Mark-to-base and mark-to-mark variation collection construct the same
row-major anchor-index lists, but do so inside each table-width template.
Pass the decoded row and class counts to a common collector.

Preserve coverage filtering, class selection, index order, and the
existing vector allocation behavior. Anchor access remains in the
format-specific wrappers.

With GCC 15.3 on x86-64 without LTO, this removes 2896 bytes of subset
code/read-only data at -O3 and 2152 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and variable-font subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>

* [ot] Share delta substitution glyph traversal across widths

Closure, dependency extraction, and glyph collection for delta
substitutions only need a decoded coverage, delta, and glyph mask.
Share those traversals instead of instantiating them for each source
representation.

Keep the closure population and overlapping-range guards, dependency
bounds filtering, traversal order, and allocation behavior unchanged.

With GCC 15.3 on x86-64 without LTO, this removes 1112 bytes of core and
952 bytes of subset code/read-only data at -O3, and 608/712 bytes at -Os.
Validated with the full Meson suite (292 passed, one skipped), C++11
syntax checking, and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>

* [subset] Share pair-position variation-index collection

Resolve the table-width-dependent PairPos fields before collecting
variation indices. Share the class sets and matrix traversal between
the small and beyond-64k formats while retaining the original value
base for device offsets.

Saves 3328 bytes at -O3 and 2312 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full test suite passes, including the
HB_NO_BEYOND_64K build; variable-font subset timings remain close.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 14:15:15 -06:00
Behdad Esfahbod c094e220c9 [ot] Erase glyph widths in contextual lookup helpers (#6398)
Contextual lookup helpers are instantiated separately for 16-bit
glyphs, 24-bit glyphs, and coverage offsets, duplicating traversal
code when beyond-64k support is enabled.

Use an allocation-free glyph-data view carrying the pointer and
element width to share matching, contextual application, intersection,
collection, closure, and dependency helper bodies. Preserve the
existing forced-inlining policy for the matching helpers.

With GCC 15.3 on x86-64 without LTO, each stripped shared library
shrinks by 12 KiB at -O3. Shaping and subset timings stay close to
baseline overall, with a measured 2% slowdown on Duployan shaping.

Validated with the full Meson suite, API/shaping/subset tests with
HB_NO_BEYOND_64K, Clang reduced-feature syntax checks, and synthetic
24-bit contextual shaping, would-apply, and glyph-collection checks.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 14:00:12 -06:00
Behdad Esfahbod 570c92b993 [subset] Share pair-position variation-index collection
Resolve the table-width-dependent PairPos fields before collecting
variation indices. Share the class sets and matrix traversal between
the small and beyond-64k formats while retaining the original value
base for device offsets.

Saves 3328 bytes at -O3 and 2312 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full test suite passes, including the
HB_NO_BEYOND_64K build; variable-font subset timings remain close.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 12:32:45 -06:00
Behdad Esfahbod f2c944c7c9 [ot] Share delta substitution glyph traversal across widths
Closure, dependency extraction, and glyph collection for delta
substitutions only need a decoded coverage, delta, and glyph mask.
Share those traversals instead of instantiating them for each source
representation.

Keep the closure population and overlapping-range guards, dependency
bounds filtering, traversal order, and allocation behavior unchanged.

With GCC 15.3 on x86-64 without LTO, this removes 1112 bytes of core and
952 bytes of subset code/read-only data at -O3, and 608/712 bytes at -Os.
Validated with the full Meson suite (292 passed, one skipped), C++11
syntax checking, and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 12:27:50 -06:00
Behdad Esfahbod ffa5d3faf1 [subset] Share retained mark-anchor index collection
Mark-to-base and mark-to-mark variation collection construct the same
row-major anchor-index lists, but do so inside each table-width template.
Pass the decoded row and class counts to a common collector.

Preserve coverage filtering, class selection, index order, and the
existing vector allocation behavior. Anchor access remains in the
format-specific wrappers.

With GCC 15.3 on x86-64 without LTO, this removes 2896 bytes of subset
code/read-only data at -O3 and 2152 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and variable-font subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 12:23:41 -06:00
Behdad Esfahbod 3e831689a9 [ot] Share SinglePos optical-bound context setup
SinglePos position_single duplicates the temporary apply context and
value application for each source representation. Keep coverage and
value-index checks in the wrappers and share the context setup through
ValueFormat, passing the original value base explicitly.

With GCC 15.3 on x86-64 without LTO, this removes 2088 bytes of core
code/read-only data at -O3 and 616 bytes at -Os. Optical-bound benchmarks
show no consistent slowdown across the four source formats.

Validated with the full Meson suite (292 passed, one skipped) and
synthetic optical-bound checks for all directions, 16/24-bit glyph IDs,
missing glyphs, and device adjustments.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 12:18:30 -06:00
Behdad Esfahbod e6827ea9da [subset] Share delta substitution subset serialization
SingleSubstFormat1_3 constructs equivalent remapping iterators in each
source-format specialization, giving the output and coverage serializers
distinct iterator types and duplicating their bodies.

Move the subset preparation into a common helper taking the decoded
coverage, delta, and glyph mask. Preserve the glyph intersection,
modular delta calculation, remapping, and serializer failure behavior.

With GCC 15.3 on x86-64 without LTO, this removes 11896 bytes of subset
code/read-only data at -O3 and 5776 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 12:13:07 -06:00
Behdad Esfahbod dafbe9c4bb [subset] Share SinglePos serializers across source formats
SinglePos output serializers only need the source value format and
ValueBase pointer, but carried the full source lookup type through
several template layers. The per-glyph mapper also had distinct lambda
types for legacy and beyond-64k source tables.

Pass the source format and base directly, and use a common mapper with
the same reference captures as the original lambda. Output formats,
device offsets, value copying, and allocation behavior are preserved.

With GCC 15.3 on x86-64 without LTO, this removes 18080 bytes of subset
code/read-only data at -O3 and 9472 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 12:08:37 -06:00
Behdad Esfahbod 4423a80460 [subset] Share mark-class remapping across record widths
Mark classes remain 16-bit values in both mark-record representations;
only the record stride and array count differ. Decode those in the
wrapper and share the class collection and remapping work.

Give the common helper hidden inline linkage so its body is shared
across translation units as well as record formats. Class ordering,
existing mappings, and allocation behavior are preserved.

With GCC 15.3 on x86-64 without LTO, this removes 1152 bytes of subset
code/read-only data at -O3 and 1440 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 11:59:38 -06:00
Behdad Esfahbod 1ea14e1cf1 [ot] Share cursive attachment positioning across table widths
CursivePosFormat1_2 duplicates the direction-dependent positioning and
attachment-chain updates for legacy and beyond-64k entry/exit records.

Keep record access and anchor validation in the format-specific wrapper,
then pass the resolved anchors to a common attachment helper. Preserve
all direction cases, chain reversal, overflow handling, and messages.

With GCC 15.3 on x86-64 without LTO, this removes another 2760 bytes of
core code/read-only data at -O3 and 864 bytes at -Os. Validated with the
full Meson suite (292 passed, one skipped) and sampled shaping benchmarks.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-15 11:55:19 -06:00