Fonts without vhea returned the ascender for the vertical descender
metric. Read the descender from the synthesized vertical font extents,
as the horizontal fallback already does.
Add a regression comparing all three fallback vertical metrics with
the font extents. It fails before this change (1024 versus -1024).
The full Meson suite passes (293 tests).
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-4UNO2SK8.
Assisted-by: OpenAI Codex
CFF1 INDEX counts are 16-bit. Serializing a larger iterator truncated
its count before reserving the offset array, then wrote offsets for
every item. Check the count before allocating or writing the offsets.
Test the CFF1 boundary and the corresponding valid CFF2 counts, and
reject a subset glyph mapping that overflows the CharStrings INDEX.
Both regressions fail before this change. The full Meson suite passes
(293 tests), including the subset and API suites.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-8ROS1VQ9.
Assisted-by: OpenAI Codex
Windows headers define small as char, so the local extent variable
breaks compilation in both MSVC CI configurations. Rename it to
small_extents.
Reproduced the failure with the macro defined and verified that the
same compilation succeeds after the rename. The MinGW cross-compiler
syntax check and full Meson suite pass (274 tests).
Assisted-by: OpenAI Codex
Changing extents during painting could allocate small group surfaces
against the original root and clip, causing out-of-bounds reads and
writes. Keep all session surfaces at the root's extents.
Use the same extents for group clear charges and pixel budget
recharges, so changing the configured rectangle cannot undercount
work on the active image. Document that render clears extents rather
than deferring a mid-session change to the next image.
Adapt the pixel regression from #6450 and check the render lifecycle.
Add an internal test for new and cached group clear charges and
budget recharging, using small buffers.
Reproduced the heap overflow on main under ASan. The budget test
fails with #6450. With this change, both raster test targets pass
under ASan+UBSan and the full Meson suite passes (274 tests).
Assisted-by: OpenAI Codex
Co-authored-by: nussaiba shaikh <nussaibah@bugqore.com>
Saturated int32 extents can round up to 2^31 when converted to float.
Clamp each scaled field before converting back to hb_position_t.
Compute width and height in double relative to the stored, clamped
bearings, preserving the existing formulas when a bearing saturates.
Adapt the COLR clip-box regression from #6459 and cover positive and
negative scales. At default scale, rounding INT32_MAX up to 2^31
leaves a one-unit extent relative to the clamped bearing.
Reproduced the original float-cast-overflow under UBSan. After the
fix, the color, extents, and font-scale API tests pass under UBSan,
and the full Meson test suite passes (273 tests).
Co-authored-by: nussaiba shaikh <nussaibah@bugqore.com>
Assisted-by: OpenAI Codex
Returning false without setting a serializer error treats the CFF
subset as empty and silently drops its outlines. Record an error when
format 1 needs more than 255 encoding ranges so subsetting fails.
Reuse the many-codes fixture to check that 255 ranges still succeed
and 256 ranges fail. The regression fails before the fix.
Testing: meson test -C build (273 passed).
Assisted-by: OpenAI Codex
A format 1 Encoding can give codes to more than 255 glyphs, since
codes may repeat across ranges. When the subset keeps more than 255
of those glyphs, as with retain-gids, plan_subset_encoding() hit
assert (subset_enc_num_codes <= 0xFF).
Choose format 0 only when it can hold the codes, and fail cleanly in
the format 1 serializer instead of truncating nRanges past 255.
Add a test font whose format 1 Encoding covers 768 glyphs, and the
reporter's font to the fuzzing corpus.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6031
Assisted-by: Claude
Assisted-by: OpenAI Codex
A subroutine can push all four seac operands, return, and leave the
glyph's own endchar to consume them. Treat callsubr and callgsubr
immediately before endchar as possible seac suffixes even when no
subroutine contains endchar.
Add a synthetic CFF1 regression font for the operand-only subroutine
case.
Assisted-by: OpenAI Codex
A subroutine can terminate a glyph with endchar, and dotsection preserves
live operands. Account for both cases when deciding whether a CFF1
charstring can form a seac composite.
Cache whether any subroutine may contain endchar so ordinary fonts keep
the fast trailing-byte check. Skip component closure when all glyphs are
already retained, except when computing reusable accelerator metadata.
Add regressions for endchar in a local subroutine and operands preserved
across dotsection.
Assisted-by: OpenAI Codex
After computing subroutine closure, reuse source charstrings and
subroutines when every retained subroutine keeps its original number.
This avoids re-encoding full identity CFF1 subsets while preserving
the existing pruning behavior when any subroutine is unused.
The full Meson test suite passes (295 passed, 1 skipped).
Assisted-by: OpenAI Codex
Clear flex-depth deltas when they all round to zero and reject unexpected
operators in the absolute-rounding pass. Cover static fractional operands
in a charstring that also contains blends.
Remove command-capture branches made redundant by the full-instancing
control flow.
Testing: meson test -C build (295 passed, one skipped).
Assisted-by: OpenAI Codex
* Don't divide by zero interpolating duplicate trak tracks
TrackData::get_tracking() brackets the requested track value (always
0 when shaping) between entries i and j and interpolates with
(track - t0) / (t1 - t0). The bracketing scan doesn't assume the
entries are sorted or distinct, so two entries that both have track
value 0.0 end with i = 1, j = 0. That skips the exact-match return
and computes 0/0. The NaN reaches hb_font_t::em_multf(), where the
cast to hb_position_t is undefined (UBSan float-cast-overflow at
hb-font.hh:1167); in practice the advance becomes INT_MIN on x86 and
the tracking is dropped on arm64.
Sanitize accepts such a table, so any font with STAT plus this trak
reaches it from hb_shape(); the CoreText font funcs call the same
getter.
Handle t0 == t1 the way TrackTableEntry::interpolate_at() already
handles equal sizes, by averaging the two values.
Added a 108-byte font to the aat-trak shape tests. It fails without
the fix and passes with it. meson test passes on an ASan+UBSan
debug build.
Assisted-by: Claude
* [aat] Pin duplicate-trak test to ot font funcs
The 108-byte test font only carries STAT and trak, with no head,
hhea or hmtx. The ot font funcs give each glyph a 500 advance, but
FreeType reports 1000 and DirectWrite refuses to load the font, so
the ft and directwrite runs of the test disagreed with the expected
output. The test only needs to exercise the trak interpolation,
so pin it to --font-funcs=ot like other minimal-font tests.
Tested with meson test -C build; the shape suites pass with
FreeType enabled.
Assisted-by: Claude
Split long CFF charset runs into format 1 chunks and compare the
resulting size with formats 0 and 2. Previously, any run longer than
256 glyphs forced all ranges to format 2.
This reduces the CFF table for NotoSansSC-Thin.otf by 13,938 bytes
without changing decoded table contents.
Assisted-by: OpenAI Codex
ContextFormat3_6<MediumTypes> (context format 6) stores its input
Coverage offsets as Offset24, but depend() passed them to
context_depend_lookup() cast to HBUINT16, so every input position
after the first decoded the wrong bytes as its offset.
intersects_coverage() then followed that value to a Coverage table
sanitize never checked.
With small offsets the misread value is 0, which points at the
subtable header, and the nested lookup's dependencies are silently
dropped. A crafted rule can instead point the misread offset at bytes
shaped like a large Coverage, and CoverageFormat1_3::intersects() reads
past the end of the GSUB blob (ASan heap-buffer-overflow via
hb_subset_depend_from_face_or_fail).
The other ContextFormat3_6 methods pass coverageZ.arrayZ + 1 as is and
let glyph_data_t pick the width. Do the same here.
ChainContextFormat3 has the same cast but only has a 16-bit
instantiation.
Add a format 6 font and test to test-ot-depend.c; it fails without
the fix. Tested with meson test under ASan+UBSan with
-Dexperimental_api=true.
Assisted-by: Claude
Without coordinates, blend_arg_t stores only a flat delta vector.
A blend used as a later blend's delta loses its own deltas, changing
outlines during partial instancing or desubroutinization.
Reject that case in the usage and flatten passes. Retained subroutine
collection needs only blend identity, and full instancing evaluates
blends numerically, so keep both paths working. Mark CFF2 planning
failures as serialization errors so the subset API returns failure
instead of a face missing its outline table.
Add a generated two-axis font and exercise retained subsetting, full
instancing, rejected partial/desubroutinized products, and supported
nested defaults. The regression fails before the fix. Full Meson suite:
272 passed, one skipped.
Assisted-by: OpenAI Codex
A partial TrueType instance can round a child's points and its
component offset independently. A later full instance at the remaining
axes' defaults recalculates bounds but leaves the source glyph header
unchanged, so it can disagree with the stored component geometry and
with the updated global bounds.
Compile glyphs through the owned-byte path for default pins as well,
and free those buffers on both serialization and failure paths.
Add a generated regression where partial instancing stores child xMax
11 and component offset 1, then default instancing must write xMax 12.
The assertion fails before the fix. The full Meson suite passes with
272 tests successful and one skipped; OTS accepts the source fixture.
Assisted-by: OpenAI Codex <codex@openai.com>
Retained subroutine remapping assumes the number preceding a call is
in the same program. Caller-supplied targets violate that assumption
and can silently change glyph outlines when unused subroutines are
removed. Enforce the existing support boundary in CFF1 and CFF2.
Report plan failures as serialization errors, rather than silently
dropping the CFF table. Explicit desubroutinization still handles the
regression fonts and preserves both outlines.
Validation: full Meson suite, 272 passed and one skipped.
Assisted-by: OpenAI Codex
Private DICT entries can accumulate several CFF2 blends before their
final operator. An eight-bit byte count truncated these spans modulo
256 during serialization, producing malformed output.
Use a full-width count and cover a 579-byte Private DICT with forty
variation regions and fourteen blended BlueValues.
Validation: full Meson suite, 272 passed and one skipped.
Assisted-by: OpenAI Codex
Rounding relative charstring operands independently accumulates errors,
opening contours and displacing stem hints after instancing. Track
absolute outline coordinates and stem edges, round their defaults and
surviving variation deltas, then emit relative operands again.
Preserve compact path operators. Conservatively retain relative rounding
for every glyph containing flex1, avoiding variation-dependent direction
analysis. Leave charstrings without blends unchanged.
Add a generated regression font covering closed contours, compact curves,
flexes, masks, and fractional static operands. Check full and partial
instances, contour closure, point accuracy, and the flex1 fallback. Refresh
the existing serialized CFF expectations.
Testing: the complete Meson suite passes (294 passed, one skipped), as do
the CFF2 API tests under ASan and UBSan.
See-also: https://github.com/fonttools/fonttools/pull/4338
Assisted-by: OpenAI Codex
When every retained glyph is empty, the glyf instancer leaves the
head bounds accumulator at its inverted initial sentinels. Reset the
accumulator after processing all glyphs so head has zero bounds.
Extend the zero-contour instruction regression to check bounds for
partial/full instances and default pins, with and without hints.
The regression fails before the fix. Full Meson: 272 passed, one skipped.
Assisted-by: OpenAI Codex
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.
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
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>
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>
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>
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
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>
* [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
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
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>
* [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>
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