* [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
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>
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>
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>
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>
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>
* [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>
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
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
* [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
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
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
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
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
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
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
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
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
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>
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>
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>
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>
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>
* [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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
When partially instancing a CFF2 font, the blend rewriters in
hb-subset-cff2.cc pass each old delta row through the region transform
and store the result with (int) round (transform_delta (...)).
transform_delta accumulates in double with no bound. Private DICT
operands can be BCD reals of any magnitude, so a StdVW blend delta of
1e12 yields about 3.7e11 at wght=300:600, and the double-to-int
conversion is undefined behavior (UBSan float-cast-overflow in
cff2_private_dict_blend_opset_t::rewrite_blends).
Saturate with hb_clamp_to<int>, as number_t::to_int already does.
The charstring blend rewriter uses the same expression and gets the
same clamp. Charstring operands are bounded by the 16.16 range, so
that site is not known to overflow in practice. Results that fit in
int are unchanged.
Add a regression test to test-instance-cff2 with a fixture generated
from AdobeVFPrototype.abc.otf. Under UBSAN_OPTIONS=halt_on_error=1 it
fails before the fix and passes after. The full Meson suite passes
under ASan+UBSan (290 ok).
Assisted-by: Claude
* [ot] Keep lookup-variation shape-plan keys compact
Resolving every feature's lookup set into the shape-plan key copies
shared lookup lists once per feature, even when shaping never uses those
features. Small fonts can therefore retain large keys and allocate
another copy on every cache lookup.
Store sorted offsets of distinct satisfied conditions instead. Evaluate
shared tables and conditions once, and expand lookup sets only when
building selected features. Preserve default lookups and feature-table
substitutions, and adapt full-axis instancing to resolve retained
features from the same compact condition state.
Condition outcomes form a conservative cache key: different outcomes
may keep otherwise equivalent lookup unions in separate plans.
Add regressions for shared records, null and shared conditions,
overlapping lookup sets, empty overrides, default lookups, sorting,
and allocation failure. The full Meson suite passes (292 passed,
1 skipped). ASan/UBSan runs pass on 64 failing-malloc inputs, and the
touched code compiles with HB_NO_VAR under C++11.
Assisted-by: OpenAI Codex <codex@openai.com>
* [test] Use an unsigned lookup condition count
Adding two boolean expressions produces an int, which GCC rejects when
compared with the unsigned vector length under -Werror=sign-compare.
This prevents the new regression test from compiling in the Linux,
docs, Rust, and Valgrind jobs.
Store the expected count as unsigned before comparing it with the
vector length. Reproduced the error with GCC C++11; the corrected test
builds and runs with GCC. The full Meson suite passes (292 passed,
1 skipped).
Assisted-by: OpenAI Codex <codex@openai.com>
get_advance_with_var_unscaled adds the HVAR/VVAR advance delta to the
base advance and returns the sum as unsigned. The delta from
ItemVariationStore::get_delta is an unbounded float, so an HVAR whose
item-variation store uses long-word (int32) deltas across several
regions that all peak at the axis extreme can make advance + roundf
(delta) exceed the unsigned range; converting that float to unsigned is
then undefined behavior (UBSan float-cast-overflow), and hb_max (0.0f,
NaN) would likewise pass NaN to the conversion. Reached from the public
hb_font_get_glyph_h_advance / v_advance on a variable font.
Clamp the accumulated value into the unsigned range with hb_clamp_to
before returning, matching the saturation already used for the
variation-derived glyph-extents arithmetic. Valid advances are
unchanged. The template is shared by hmtx/HVAR and vmtx/VVAR, so all
three advance sites are covered.
Add a regression test under test/api driving a crafted long-word HVAR;
it reports float-cast-overflow under the sanitizers job without the fix
and passes with it. The full meson test suite passes.
push (v[i]) reads its argument after alloc() may have moved the
vector's backing storage. Array extension has the same problem.
This is reachable through item_variations_t::duplicate_row() when
subsetting avar2 axes that share a variation row.
Construct a temporary before growth when a push argument aliases our
storage, and recover aliased source arrays by offset after allocation.
Keep the alias check on the push growth path, and reject already-failed
vectors before moving from their arguments.
Share the array extension implementation and route direct vector
extension through it, making v.extend (v) safe as well. General iterator
adapters into the same vector still cannot survive reallocation.
Add regressions for trivial and non-trivial copies, aliased moves,
constructor arguments, mutable and const arrays, direct self-extension,
and already-failed vectors. Reproduced push and both extension failures
under ASan before the fix. The updated tests pass under ASan+UBSan and
GCC with HB_TINY; injected allocation failures are clean under the
sanitizers. The full Meson suite passes (292 passed, 1 skipped).
Assisted-by: Claude
Assisted-by: Codex
Co-authored-by: Mar <mardgez13@gmail.com>
IBM i and AIX use XCOFF, which rejects hidden visibility on references
to imported inline symbols. This can prevent test-repacker from linking
against libstdc++.
Disable inline visibility hiding for these hosts in Meson and CMake,
while preserving the existing setting on other systems.
The full configured Meson suite passed (288 tests), and a native CMake
shared-library build succeeded. Platform-policy checks cover AIX,
OS400, Linux, macOS, and Windows. Native IBM i/AIX was unavailable.
Co-authored-by: Chi-Iroh <69324626+Chi-Iroh@users.noreply.github.com>
Assisted-by: OpenAI Codex
COLR closure returned before planning delta-set index mappings when
there was no store or no live variation index. Variable paint and stop
serialization then failed to find their remapped bases, dropping COLR.
Remap explicit delta-set indices even when every entry is the
NO_VARIATION_INDEX sentinel. Keep variation-row planning conditional on
live rows. Cover NULL and empty stores with ordinary subsetting,
partial instancing of either axis, and full instancing.
Testing: meson test -C build passed 271 targets, with one skip.
Assisted-by: OpenAI Codex
Instancing PaintVarTransform loses low Fixed bits when the stored base
is converted to float before adding its delta. This occurs at ordinary
translation values and even when the delta is zero.
Add the float delta to the precise stored integer in double precision,
then round to the target Fixed integer. Preserve the existing default
coordinate fast path.
Cover all six coefficients, signed and zero deltas, and direct and
composed instances in both axis orders at ordinary magnitudes. The
pre-fix library fails the translation regression. All 256 configured
Meson tests pass, and all 28 matrices match FontTools exactly in each
instancing order.
Assisted-by: Codex
Reparameterize circles and color stops together when a derived radius
is negative. Preserve pad, repeat, reflect, and stable stop ordering.
Normalize constant gradients after a partial pin without creating
constant variation regions at the new default.
Allow fractional parameter shifts on the common lattice of the circle
coordinates and F2Dot14 stops. This preserves odd stop bits in ordinary
coordinate ranges that integer-only shifts incorrectly rejected.
Assisted-by: Codex
Round minimum clip edges down and maximum edges up in font units.
Nearest rounding can shrink bounds and cut painted pixels.
Cover signed fractional deltas, default coordinates, rendering, and
full/composed instances in both axis orders at ordinary values.
All 256 configured Meson tests passed.
Assisted-by: Codex