The RuleSet fast paths filtered out rules requiring another glyph when
the skipping iterator reached the end of the buffer. Unlike the normal
rule walk, that early return did not record the resulting
unsafe-to-concat range.
Keep the end-of-input optimization, but track filtered rules and mark
their concat hazard before returning. Cover both contextual and chained
contextual rule sets with a five-rule font that forces the fast paths.
Assisted-by: OpenAI Codex <codex@openai.com>
A zero-valued PairPos record can select a different, non-zero record
if the second glyph changes, so keep the pair unsafe to concat even
when no positioning was applied.
Likewise, make the ligature second-glyph digest rejection report the
same hazard as the full ligature walk.
Tests: meson test -C build
Port of https://github.com/harfbuzz/harfrust/pull/465
Assisted-by: OpenAI Codex <codex@openai.com>
U+180F MONGOLIAN FREE VARIATION SELECTOR FOUR was added in Unicode
14.0 and has Default_Ignorable_Code_Point=Yes, but
is_default_ignorable() only covered U+180B..180E, so FVS4 was never
hidden and leaked a .notdef into the output.
8c65442069 ("[Unicode 14] Handle U+180F FVS4") added the U+180F case
to _hb_glyph_info_set_unicode_props() and to the Arabic shaper, but
that branch sits inside "if (unicode->is_default_ignorable (u))", so
it has been unreachable since it was written. Extending the range to
U+180B..180F makes it live.
U+180B..180F are all Default_Ignorable_Code_Point per
DerivedCoreProperties.txt, so the range stays contiguous.
Before, with a font with no Mongolian coverage:
$ hb-shape Roboto-Regular.abc.ttf -u U+0061,U+180F
[1=0+1114|0=0@-908,0+0]
Every other default ignorable (U+180B..180E, U+FE00, U+200B) on that
font shapes to [1=0+1114]. After the change U+180F matches them.
Added two cases to mongolian-variation-selector.tests, which already
covered FVS1, FVS2, FVS3 and MVS but not FVS4: U+180F, and U+1810
MONGOLIAN DIGIT ZERO to pin the top of the range so it cannot be
widened by accident.
Tested with "meson test -C build": 254/254 OK, 0 failures. Restoring
the old U+180B..180E fails in-house 6174/6176, and widening it to
U+180B..1810 fails the same way.
Assisted-by: claude-opus-5
Co-authored-by: Dylan Pulver <dylanpulver@users.noreply.github.com>
FreeType requires face creation and destruction on a shared
FT_Library to be serialized. Protect the lazily-created static library,
its reference count, and its internally-owned faces with a lazy mutex.
Keep caller-owned FT_Library instances outside the new lock, and add a
multithreaded regression test for blob-backed faces and font funcs.
Tests: meson test -C build (272/272 passed)
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6224
Assisted-by: OpenAI Codex <codex@openai.com>
context_depend_lookup and chain_context_depend_lookup build the
input-position glyph sets with for (i = 0; i < inputCount - 1; i++),
so a Rule with inputCount 0 (what a null rule offset resolves to)
underflows the bound to UINT_MAX and reads past the object into the
Null pool. Rewrite both loops as i + 1 < inputCount, matching the
guarded inputCount handling used everywhere else in the file. Reached
from hb_subset_depend_from_face_or_fail on a crafted GSUB context
rule; seed added under test/fuzzing/fonts.
context_depend_recurse_lookups tracks covered sequence positions in
a fixed hb_bit_page_t, but the dependency-graph path never bounded
inputCount the way the shaping apply path does. A crafted GSUB
contextual rule with glyphCount past the page (e.g. 512) and a
SubstLookupRecord whose sequenceIndex lands in a higher page element
than endIndex makes hb_bit_page_t::add_range compute its memset
length as (char*)lb - (char*)la, which is negative and wraps to a
huge size_t, writing past the stack-allocated page. Reachable from
hb_subset_depend_from_face_or_fail on a crafted face.
Cap inputCount at HB_MAX_CONTEXT_LENGTH before the page is used,
matching the apply path; rules longer than that never apply during
shaping, so no real dependency edges are lost. Adds a regression
seed exercised by the depend fuzzer.
When the requested direction differs from the script's horizontal
direction, the Graphite2 shaper reverses the buffer before segmenting.
Input cluster values then decrease along the buffer, so assigning each
Graphite group the cluster of its base character can leave earlier
characters outside the resulting cluster map.
Preserve the source span of every Graphite glyph while constructing the
output. At monotone cluster levels, seed each glyph from the minimum
endpoint of that span and use merge_clusters() over each Graphite output
range. Keep the historical base-character behavior at non-monotone
levels.
HarfBuzz cluster values are opaque client labels and can be repeated or
gapped. Merging them can therefore coalesce multiple Graphite layout
groups. Preserve the Graphite group index separately for positioning so
every group's advance is emitted even when its HarfBuzz cluster was
merged. Validate Graphite slot source bounds before indexing the input.
Add shape regressions using a subset of Awami Nastaliq and an API test
with repeated input clusters. The latter used to merge the output
clusters correctly but drop an entire layout-group advance, reducing
the total from 3200 to 1269.
Tested with:
meson test -C build test-graphite2
meson test -C build --suite shape
meson test -C build
Assisted-by: Codex <codex@openai.com>
Co-authored-by: Michael Brown <michael.brown@rubicotech.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
The Noto Nastaliq fixtures dominate the runtime of a 64-font dependency
closure-parity chunk, obscuring both their cost and the runtime of the
remaining fixtures.
Run each Noto Nastaliq font as its own named test while retaining the
same seed and per-font test count. Keep all other fonts in the normal
chunking flow.
Tested with the full Meson test suite (272/272 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
Expose the exact set-intersection query so callers can test whether two
sets have any elements in common without copying and mutating a set.
The implementation handles inverted sets through the internal helper.
Document the new API with its release placeholder, add it to the docs
section index, and cover regular and inverted set combinations.
Tested with the full Meson test suite (270/270 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
Contextual GSUB dependency collection revisits completed lookup states
through each parent path. Complex Nastaliq lookup graphs therefore spend
minutes repeatedly expanding identical subgraphs.
Intern the recursion inputs and cache completed states per top-level
lookup. Remove unused contextual stack bookkeeping and avoid temporary
set allocation for exact intersection checks. Re-enable the Nastaliq
closure-parity fixtures now that they complete quickly.
Tested with the full Meson test suite (270/270 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
The thread-safety test shaped entire books and a twelve-thousand-line word
list in every worker. That made it behave like a benchmark even though
the races it targets are exercised when threads concurrently initialize
and use a shared font.
Use the existing substantial paragraph corpora instead. They retain
Latin and Arabic-script coverage across every font backend and both
variable-font modes while reducing standalone runtime from about 1.09s
to 0.16s.
Also reset the worker start gate for every backend so each combination
actually begins concurrently instead of only synchronizing the first.
The full 270-test Meson suite passes, as does an 8-thread, 5-repetition
stress run.
Assisted-by: OpenAI Codex <codex@openai.com>
The vector and raster output APIs generate a single glyph asset for
embedding by their caller, but their fuzzers accumulated the first 16
glyphs into one output document. Select one of those glyphs from the
fuzz input instead, retaining coverage across the original range
without multiplying per-glyph work in one invocation.
Tested with the fuzzing suite and the full Meson test suite.
Assisted-by: OpenAI Codex <noreply@openai.com>
The explicit 120-second timeouts were added after raster-fuzzer chunks
exceeded Meson's 30-second default under MALLOC_PERTURB_. The dominant
cost was an oversized temporary PNG decode buffer, which is now rejected
before allocation.
Restore the default timeout so future runaway fuzz inputs fail promptly
instead of being hidden by extra headroom.
This reverts commit fbdac41be3.
Testing: meson test -C build
Assisted-by: OpenAI Codex <noreply@openai.com>
The raster-fuzzer chunks occasionally hit meson's default 30s test
timeout on CI (e.g. raster-fuzzer-chunk-5 at 30.8s on linux main).
The dominant cost is not the fuzzer inputs themselves: meson runs
tests with MALLOC_PERTURB_ set, which makes glibc scribble over
every allocation on free. Fuzz inputs that acquire large raster
surfaces (up to 4096^2, 64MB) normally leave most pages untouched,
but the perturbation forces a full memset and page-in on free, so a
chunk that runs in ~1.1s bare takes ~7.7s under meson locally
(~6s of it system time), and brushes 30s on slower shared CI
runners. Which chunk is affected varies by machine because the
fonts glob is not sorted, so chunk membership differs.
Keep the perturbation (it catches real bugs) and raise the timeout
of the chunked fuzzing tests to 120s instead, in line with other
suites (subset: 500, threads: 300, perf: 100).
Fuzzing suite passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The seed's COLR paint walk fills glyphs whose gvar-varied cubics have
astronomically large control points; each curve recursed to the full
depth-16 subdivision cap while emitting no edges, invisible to the
edge-based paint budget. Timed out on ClusterFuzz before the two
preceding commits.
https://oss-fuzz.com/testcase-detail/4912367159541760
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The seed's COLR paint walk emits a full 16MB vector-paint work
budget of path text from a single large gvar-varied glyf glyph;
before the preceding commit the snprintf-based number formatting
made that blow the 60s ClusterFuzz timeout on i386 ASAN builds.
https://oss-fuzz.com/testcase-detail/4700345193005056
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
An avar version 2 table with a NULL varStore offset is legal and maps
like plain v1 — but partial-instancing it used to fail outright, because
the planner errored against the missing store. Rather than falling back
to the v1 instancing path (which rescales every variation store and is
not always bit-exact), keep such fonts on the avar2 path: mapping
entries that don't resolve to a real store row are normalized to
NO_VARIATIONS_INDEX, mirroring runtime get_delta semantics, and offset
compensation creates the needed delta rows on demand in an empty store.
The instance stays version 2 and bit-exact, and consumers that ignore
the v2 tail still see the renormalized v1 segment maps.
Adds a subset test with a null-VarStore variant of the RobotoDelta test
font; the instancing test fails outright without the fix.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The subset planner rejected out-of-range avar2 delta-set indices even
though runtime evaluation treats them as zero. The avar2 rewrite also
carried those invalid indices into its output mapping.
Validate delta-set indices centrally and normalize invalid mappings to
NO_VARIATION_INDEX during planning and rewriting. Add coverage for an
empty non-NULL VarStore with an implicit index map.
Tests: meson test -C build
Assisted-by: OpenAI Codex
Under the fuzzer's failing-malloc allocator, the font drives a COLR
paint graph whose session initialization fails its stack push and
then re-cleared a 4096x4096 root surface on every one of ~2240
paint callbacks, timing out on ClusterFuzz before the previous
commit.
https://oss-fuzz.com/testcase-detail/4604877465255936
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The font drives two sweep gradients with 27648 color stops over an
angular span of ~0.0008 rad with a repeat extend, previously
emitting ~140M Coons patches in the PDF vector backend and timing
out on ClusterFuzz before the preceding two commits.
https://oss-fuzz.com/testcase-detail/6490910482038784
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Widen position differences before taking their absolute value. This
avoids signed overflow when hb_buffer_diff() compares positions near
opposite ends of the hb_position_t range.
Add an API regression covering INT32_MIN versus INT32_MAX.
Tested with: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
The edge-work estimator cast the result of the y-coordinate
subtraction to int64_t, after the subtraction had already happened in
int32_t. An edge spanning the clamped coordinate range could therefore
overflow before the work was capped to the surface height.
Widen both operands before subtracting, matching the existing edge
slope calculation, and add the minimized OSS-Fuzz reproducer to the
fuzz corpus.
Fixes: https://oss-fuzz.com/testcase-detail/5773854015029248
Assisted-by: OpenAI Codex <noreply@openai.com>
Mark-to-mark attachment can accumulate an unbounded cross-direction
offset. Clamp anchor conversion and saturate the immediate addition so
overlong mark clusters stop at hb_position_t limits instead of invoking
signed-overflow undefined behavior.
Add a regression for issue #6151 using 35,000 combining marks.
Testing: meson test -C build --print-errorlogs
Assisted-by: Codex <codex@openai.com>
SubsetGlyph stores borrowed slices into the source glyf table. Faces
created with a table callback may return a fresh blob on each request,
so destroying the population accelerator left those slices dangling
before they were serialized.
Retain the exact glyf blob through serialization. Exercise this path
by making the existing create-for-tables test return copied blobs.
Reported by WinD39 - Huynh Dinh Vu.
Fixes: https://issues.chromium.org/issues/536584255
Assisted-by: OpenAI Codex <codex@openai.com>
The raster seed drives ~2048 COLR PaintComposite nodes each costing
a full-surface composite; the gpu seed drives a VARC composite glyph
whose components each load a large glyf leaf glyph. Both timed out
on ClusterFuzz before the preceding work-budget commits.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
When no extents are set explicitly, the paint and draw contexts
derive the surface size from font data: glyph extents (which the
auto path in hb_raster_paint_glyph_impl () feeds through
set_glyph_extents ()) or the accumulated outline bounds in
hb_raster_draw_render (). A malicious font with a tiny upem and
huge glyph coordinates turns that into arbitrarily large
allocations: a 49 KB fuzz font produced several ~885 MB BGRA
surfaces live at once (root surface plus one per PaintComposite
push_group), nearly 4 GB total.
Add HB_RASTER_MAX_AUTO_DIMENSION (4096) to hb-limits.hh and clamp
width/height at the three font-derived sizing points: both
set_glyph_extents () implementations and draw render's
auto-size-from-edges path. Since push_group and clip surfaces
inherit fixed_extents, the cap bounds those too. Extents set
explicitly via hb_raster_{draw,paint}_set_extents () are not
limited.
Fixes an hb-raster-fuzzer out-of-memory finding (testcase
6344015149858816): peak RSS 3.47 GB before, 350 MB after.
Testcase added as a fuzz seed. Full meson test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
edge_sweep_row () computed y_bot = y_top + ONE_PIXEL in int32. The
scanline loop clamps y_top itself to INT32_MAX, but when the surface
sits at the extreme of the 24.8 fixed-point coordinate space y_top
can be within ONE_PIXEL of INT32_MAX (0x7FFFFF00), and the addition
overflows: UBSan "2147483392 + 256 cannot be represented in type
'int'".
Saturate the addition at INT32_MAX using the same 64-bit-then-clamp
idiom already used for y_top and the x interpolation. Edges are
int32-clamped too, so no coverage exists beyond INT32_MAX and the
clipped bottom band loses nothing real.
Fixes ClusterFuzz issue 541858526 (testcase 5513551012495360).
Reproduced with a -Db_sanitize=undefined build: one UBSan report
before, clean after. Testcase added as a fuzz seed. Full meson
test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
When instancing, the hmtx/vmtx advance is computed by adding the
HVAR/VVAR delta to the base advance. The delta is attacker-
controlled and unbounded, so the sum can go negative or exceed
65535. The negative case, cast to unsigned, produced advances
near 4 billion in hmtx_map; CFF::optimize_widths () then looped
over the full [min_w, max_w] width range, taking minutes (the
oversized cumsum resize fails cleanly, so this was a pure hang,
no memory unsafety).
Clamp the computed advance to [0, 0xFFFF], matching the UFWORD
range that hmtx/vmtx serialization stores and the hb_max (0.f, …)
clamp already used by the runtime metrics path.
Fixes a ClusterFuzz timeout in hb-subset-fuzzer (testcase
4846730722738176, minimized from timeout-fd8f4bd2a650). The
testcase went from >60s to 5ms; added as a fuzz seed. Full
meson test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Insertion state machines may emit glyphs during the end-of-text transition, when the buffer has no current input glyph. Emit the glyph first in that case and apply AAT metadata to the new output glyph instead of buffer->cur().
Add a regression font whose end-of-text action inserts the AAT deleted-glyph sentinel.
Assisted-by: OpenAI Codex <noreply@openai.com>
The fragment shader picks one horizontal and one vertical band from
the fragment position and walks only that band's curve list, so a
curve must be listed in every band its bounding box reaches into.
The encoder computed those bounding boxes from the unquantized
control points, but the shader only ever sees the coordinates after
they are rounded to quarter font units. When rounding pushed a
curve's extreme across a band boundary, the curve was left out of the
band it now reached into. Fragments landing in that sliver never saw
the curve, so their winding number was off by one and the pixel came
out empty in the middle of a filled area -- a thin black line through
the glyph, appearing and disappearing as the font size moves the
pixel grid.
The rounding error is at most an eighth of a font unit, so this is
invisible for an integer-coordinate glyph rendered at its own upem.
It gets easy to hit when the coordinates are fractional: CFF glyphs
after cu2qu, or any font whose hb_font_t scale is not its upem. With
hb_font_set_scale(font, 163, 163), as in issue #6131, more than half
of the glyphs of util/gpu/default-font.ttf had at least one band the
shader could reach but that did not list the curve.
Compute the bounds (and the is_horizontal/is_vertical tests) from the
quantized control points instead, and widen the band range by 1/1024
of a band so that the double arithmetic here cannot disagree with the
shader's float32 band index right at a boundary.
Verified with a CPU port of _hb_gpu_slug_single: comparing the banded
lookup against a walk over every curve of the glyph, at sizes 39, 47
and 107 with scale 163, default-font.ttf had 27 wrong pixels before
and none after. Encoded atlas size grows by 0.12%.
Adds test_encode_band_membership, which checks the invariant directly
on the encoded blob and fails before this change.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
For fetching various bit fields scattered around OpenType tables. Many of
these are legacy or unreliable, but applications might need them for
various legacy reasons.
Fixes https://github.com/harfbuzz/harfbuzz/issues/1920
* [test/fuzzing] Skip hb-depend-closure-parity without GLib
It depends on GLib unlike the other fuzzers.
* [ci] Build the msan bot without external dependencies
We don’t care about msan errors in code that is not ours, and some
libraries like GLib are not built with memory sanitizers in mind.
* [ci] Don't pipe sanitizer test output
The pipe was masking meson exit status, and it was redundant anyway
since the sanitizer output is is already symbolized and demangled.
* [COLR] Fix integer overflow in get_extents
Use to_glyph_extents(), which guards against this.
Update test expectation since we now round instead of truncate.
Fixes https://github.com/harfbuzz/harfbuzz/issues/4596
See the issue for more details.
Instead of deferring mark positioning to the end of GPOS application, we
now apply cross-direction offsets (y-direction in horizontal text)
immediately and keep applying main-direction (x-direction in horizontal
text) as before.
This is still not 100% compatible with DirectWrite or Core Text (they
apply both directions immediately), but enough to fix the reported
issue.
Based on Behdad’s patch below, but fixes the Noto Nastaliq regression by
resolving the base offset through the whole cursive attachment chain
since cursive offsets are relative the previous glyph and get finalized
only at end of GPOS:
https://github.com/harfbuzz/harfbuzz/issues/4596#issuecomment-2276300688
The remaining failure is not a regression, the new expectation now match
DirectWrite and Core Text.
The tests include a subsetted bug font, as well as two constructed fonts
where curs lookup come before mark ones, once with kern before mark and
with kern after mark, to show that lookup order affects y but not
x-direction.