Commit Graph
603 Commits
Author SHA1 Message Date
Behdad Esfahbod d997502000 [meson] Guard tests for disabled optional libraries (#6335)
* [meson] Skip vector tests when vector is disabled

The vector budget test was built unconditionally even when vector was
explicitly disabled. Its empty dependency supplied neither include paths
nor libraries, breaking otherwise valid reduced-feature builds.

Skip the vector test directory when the library is disabled. Add a Linux
CI build and test pass with vector disabled to cover this configuration.

Reproduced the missing hb.h failure on Linux before the fix. The full
suite with vector, raster, and GPU disabled passed 229 tests with one
skip; all three vector tests passed with vector enabled.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6277
Assisted-by: OpenAI Codex <codex@openai.com>

* [ci] Remove extra vector-disabled build pass

Keep the fix focused on guarding the vector test directory without adding
another build and test pass to the Linux workflow.

CI-only change; the previously validated Meson guard is unchanged.

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

* [meson] Guard dependency fuzzers when subset is disabled

With experimental APIs enabled, dependency fuzzers referenced
libharfbuzz_subset even when the subset library was disabled, causing
Meson setup to fail with an unknown-variable error.

Require subset support when building the dependency fuzzers and when
registering their tests.

Full tests with experimental APIs enabled: 92 passed with subset
disabled, and 247 passed with subset enabled. Both dependency fuzzers
and their 13 tests remain registered in the enabled configuration.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-07 12:55:53 -06:00
Behdad Esfahbod a52249ff62 Merge pull request #6326 from harfbuzz/fix/cff2-fdselect-varc
[subset] Bound CFF2 FDSelect lookups by the CharStrings count
2026-10-06 19:34:36 -06:00
Behdad EsfahbodandClaude Sonnet 5.5 e6d5454350 [paint] Clamp hb_color_lerp() channels to [0,255] (#6305)
Sweep-gradient color-stop angles come from the font, so the
interpolation fraction t can fall outside [0,1] (or be NaN).  The
interpolated channel was then cast float -> unsigned directly; a
negative value (e.g. -387.671) is UB (UBSan float-cast-overflow) and
yields meaningless colors on release builds.

Clamp the interpolated channel to [0,255], mapping NaN to 0, before
the cast.  In-range behavior is unchanged.  Add the reported fuzzer
input as a seed.

Reported by iceray-Li.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 18:22:41 -06:00
Behdad EsfahbodandClaude Sonnet 5.5 b7fca823a0 [avar] Clamp instantiated axis-value maps to F2DOT14 range (#6303)
AxisValueMap::instantiate() renormalizes the from/to coordinates and
stores them with set_float() without clamping.  With malformed input
the result can fall outside [-1,1] (e.g. 2.192 -> 35923), overflowing
the int16 F2DOT14 storage: UB under UBSan's float-cast-overflow, and a
silently truncated avar table otherwise.

Clamp both coordinates to [-1,1] before storing.  Add the reported
fuzzer input as a seed.

Reported by iceray-Li.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 18:03:28 -06:00
Behdad Esfahbod b3bab62307 [VARC] Clamp component axis coordinates (#6274)
Axis-value variation deltas can push a rounded component coordinate
outside the range of int. Assigning that float to coord_setter then
triggers undefined behavior in the conversion.

Use hb_clamp_to<int>() after rounding, preserving in-range behavior
while saturating extreme values. Add the minimized raster-fuzzer input.

Tested with meson test -C build and the ASan/UBSan raster fuzzer.

Assisted-by: OpenAI Codex
2026-09-21 12:15:48 -06:00
Behdad EsfahbodandClaude Fable 5.1 64e2b53235 [glyf] Charge point loading to the work budget before doing the work (#6256)
The glyf outline budget was only charged after a glyph loaded
successfully: Glyph::get_points() spent 16 units per node up front, and
glyf_accelerator_t::get_points() charged one unit per point only after
the whole tree came back.  A glyph that loaded ~175K points and then
tripped a structural cap (HB_GLYF_MAX_POINTS, edge count) paid for the
nodes but not the points.  Driven from a COLR paint walk through
hb_font_get_glyph_extents(), one such glyph was loaded and thrown away
over 8000 times per session within the budget, ~1.4G point loads.

Charge at the point where the work is attempted instead:

- SimpleGlyph::get_contour_points() takes the budget and charges
  num_points before allocating, clearing, and reading, so truncated or
  later-rejected glyphs pay for the points they allocate.

- Composite levels charge the component subtree size before
  transform_points(), since each nesting level transforms every point
  below it and that multiplication was previously invisible to the
  budget.

The terminal per-point charge for path emission is unchanged.

Local hb-vector-fuzzer run on the testcase: 4.3s -> 0.12s.  Full test
suite passes.  The testcase is added as a fuzz seed.

Fixes: https://oss-fuzz.com/testcase-detail/5714817420427264


Claude-Session: https://claude.ai/code/session_013ksLGe7wUVwbuANqR56YaN

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-10 22:19:47 -06:00
Behdad Esfahbod 3baafbcb3d [raster] Clip the edge sweep's column walk to the surface (#6251)
* [raster] Clip the edge sweep's column walk to the surface

edge_sweep_row() walked every fixed-point pixel column an edge spans,
even though columns right of the surface contribute nothing and
columns left of it only contribute a cover delta that telescopes into
column 0.  A near-horizontal edge with extreme coordinates could span
~2^24 columns per row, making sweep cost proportional to coordinate
range instead of surface width: the ClusterFuzz testcase took 114s in
a plain release build.

Fold the left-of-surface portion of the walk into a single column-0
cover update, skip the right-of-surface portion, and enter/exit the
per-column loop at the visible window.  Jumping the incremental fy
accumulator by k*delta_fy is exact, since the increment is constant
and the running sums are bounded, so output is bit-identical; verified
by comparing 178 hb-raster renders (draw and paint paths, several
fonts, sizes, and negative-margin crops that clip edges off-surface)
byte-for-byte against the previous code.  The testcase now runs in
0.17s.  Also add it as a fuzz seed.

Fixes https://oss-fuzz.com/testcase-detail/5267980968329216

Assisted-by: Claude Fable 5 <noreply@anthropic.com>

* [raster] Keep an unclipped fast path in the edge sweep

The window clipping added in the previous commit made every
multi-column edge-row pay for the clip setup, measurable as ~1% more
instructions rasterizing all glyphs of NotoSansCJKsc/SourceHanSans-VF
at 256px with hb-raster-all.  Guard it with a two-compare
fully-inside-the-surface check and walk such edges with the original
unclipped code, which is also the everyday case: auto-sized surfaces
always contain their edges.

Interleaved perf-stat A/B (5 rounds, all glyphs at 256px): instruction
overhead drops to +0.24% (CJK) / +0.9% (AwamiNastaliq, tiny workload);
cycles flat to -1.3%, within noise.  Output remains bit-identical on
the 178-render comparison matrix, and the oss-fuzz 5267980968329216
testcase stays at 0.19s.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>

* [raster] Charge column spans in the pixel-work estimate

hb_raster_draw_get_pixel_work() charged each edge only its scanline
span, so a nearly-horizontal edge crossing one pixel row but sweeping
the full surface width cost up to `width` cells while being charged 2
units — the paint path's pixel-budget precharge could undercharge the
sweep by a factor of the surface width.  This is the same blind spot
that let the previous commits' column-walk timeout through the paint
path's precharge.

Charge each edge its column span too, clipped to the surface width the
same way the row span is clipped to its height.  Since an edge is a
straight segment, row span plus clipped column span is a true upper
bound on the post-clipping sweep work.  Normal outlines are barely
affected: flattening yields short segments whose column spans are
commensurate with their row spans, far below the 2^26 budget.

No rendering change: the 178-render comparison matrix remains
bit-identical and the full test suite passes.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-10 14:30:09 -06:00
Behdad Esfahbod 46ea946ab4 Merge pull request #6214 from harfbuzz/rendering-work-budgets
[limits] Add rendering work budgets
2026-09-06 16:36:58 -06:00
Behdad Esfahbod 037aa79451 [fuzzing] Add rendering budget timeout seeds
Add the minimized vector, raster, and GPU testcases that exercise the
aggregate outline-expansion timeout.  Keeping the OSS-Fuzz testcase IDs
in their filenames makes each regression directly traceable.

The current leaf-level limits allow all three inputs to complete in the
optimized test build; later aggregate accounting will reduce their work
further.

Tests: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-26 16:41:49 -06:00
Garret Rieger 5f16f4ba68 In pair pos format 2 splitting only recompute coverage size when the included glyph set changes.
Assisted by Gemini
2026-08-26 14:24:53 -06:00
nussaibah shaikh 64dab85712 [depend] avoid inputCount underflow in context depend loops (#6211)
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.
2026-08-26 08:52:19 -06:00
nussaiba shaikh 66ef3397ea [depend] Bound context inputCount to HB_MAX_CONTEXT_LENGTH
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.
2026-08-24 14:57:59 +05:30
Behdad Esfahbod 7584482381 [test] Isolate Noto Nastaliq depend parity tests
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>
2026-08-19 16:14:40 -06:00
Behdad Esfahbod 8fe7910b00 [depend] Memoize contextual lookup recursion
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>
2026-08-19 15:53:15 -06:00
Behdad Esfahbod a229ba9c0a [fuzzing] Render one vector or raster glyph per input
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>
2026-08-19 13:33:50 -06:00
Behdad Esfahbod bf60bb7460 [test] Restore default fuzzing timeouts
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>
2026-08-19 13:12:32 -06:00
Garret Rieger 6c2107ace7 Fix arithmetic overflows in IUP handling.
Fixes https://oss-fuzz.com/testcase-detail/4688270404157440.
2026-08-17 19:09:43 -06:00
Behdad Esfahbod d54151cf08 Merge pull request #6169 from harfbuzz/raster-flatten-clip
[raster] Clip and budget Bézier flattening
2026-08-17 17:10:07 -06:00
Behdad Esfahbod fbdac41be3 [test] Raise timeout of chunked fuzzing tests to 120s
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>
2026-08-17 15:21:24 -06:00
Behdad Esfahbod c1b4afecfa [test] Add fuzz seed for raster flattening timeout
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>
2026-08-17 14:38:00 -06:00
Behdad Esfahbod beae23d0a7 [test] Add fuzz seed for vector number-formatting timeout
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>
2026-08-17 14:14:28 -06:00
Behdad Esfahbod dfdc088c4d Merge pull request #6158 from harfbuzz/fix-raster-surface-clear
[raster] Stop re-clearing the root surface after failed initialization
2026-08-13 12:48:03 -06:00
Behdad Esfahbod 7244b5da86 [test] Add fuzz seed for raster surface re-clear timeout
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>
2026-08-13 12:09:54 -06:00
Behdad Esfahbod 738e09b075 [test] Add fuzz seed for sweep-gradient tile timeout
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>
2026-08-13 11:48:04 -06:00
Behdad Esfahbod 87440579f9 Fix a couple of warnings 2026-08-13 08:43:50 -06:00
Behdad Esfahbod 1f30c6d4cc [raster] Widen edge-span subtraction (#6153)
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>
2026-08-12 18:27:36 -06:00
Behdad Esfahbod 3344283d4a [test] Add fuzz seeds for budget-multiplication timeouts
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>
2026-08-10 14:27:56 -06:00
Behdad EsfahbodandClaude Sonnet 5 bbfe29975d [raster] Cap font-derived surface dimensions at 4096 pixels per side
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>
2026-08-10 13:14:53 -06:00
Behdad EsfahbodandClaude Sonnet 5 c2b6b09ed2 [raster] Fix signed overflow computing row bottom at coordinate limit
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>
2026-08-10 12:55:45 -06:00
Behdad EsfahbodandClaude Sonnet 5 d94c18b6a6 [subset] Clamp variable advances to UFWORD range in plan
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>
2026-08-10 12:47:41 -06:00
Khaled Hosny 9d7bba088a Try to fix msan bot (#6124)
* [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.
2026-07-30 19:02:25 -06:00
Behdad Esfahbod c5eda499b4 Merge branch 'main' into codex-review-pr-5733 2026-07-30 11:40:20 -06:00
Behdad Esfahbod 25fc94439a Merge pull request #5733 from skef/depend-draft-pr
OpenType font dependency graph support
2026-07-30 11:12:48 -06:00
Nussu06 1737bce456 [subset] bound cvar tuple data length in calculate_cvt_deltas 2026-07-18 07:25:19 -06:00
Behdad Esfahbod 41ec50d54b [subset] Include serialize API from subset header
The subset umbrella header already carries the public subset API, but it
missed hb-subset-serialize.h even though the serialize symbols are part
of the subset section. Include the serialize header from hb-subset.h so
users can get the API through the top-level subset header.

Keep hb-subset-serialize.h directly includable for compatibility, but
emit a diagnostic asking users to include hb-subset.h instead. Update the
local repacker tests to use the umbrella header and verify the API is
available there.

Testing: meson compile -C build test/api/test-subset-repacker test/fuzzing/hb-repacker-fuzzer
Testing: meson test -C build --suite api
Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-07-14 12:01:38 -06:00
Behdad Esfahbod c6c9c7c53f [test] Bound depend parity fuzzer runtime
The depend closure parity Meson test ran 1024 random cases per font over
large chunks. That made a single test spend excessive time repeatedly
walking huge cmap data, and the Noto Nastaliq fonts currently spend tens
of seconds or more in contextual GSUB dependency graph construction
before parity comparisons even start.

Cache the unicode-to-glyph map per font, select codepoints with one
linear pass over the cmap, and avoid glyph-starting non-GSUB tests for
huge-cmap fonts. Limit the Meson parity workload to a smaller fixed
sample and skip the two known Nastaliq graph-construction outliers until
that algorithmic path is made fast enough for the default test suite.

Testing: meson test -C build depend-fuzzer-chunk-7 depend-closure-parity-chunk-0
Testing: meson test -C build --suite api
Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-07-14 11:56:05 -06:00
Behdad EsfahbodandClaude Opus 4.8 9072836ef5 [vector-pdf] Fix indexed-PNG tRNS soft-mask dimension overflow
hb_pdf_build_indexed_smask() computed its buffer sizes with unchecked
32-bit arithmetic:

    unsigned raw_len = (width + 1) * height;
    ...
    out->resize (width * height);

width/height come straight from the attacker-controlled PNG IHDR (the
vector-PDF path re-parses IHDR itself and does not clamp dimensions,
unlike sbix).  For width = height = 65536, (width + 1) * height wraps to
65536 and width * height wraps to 0.  A crafted IDAT inflating to the
wrapped raw_len passes the length check, the mask buffer is resized to
zero, and the per-pixel loop then writes through out->arrayZ[y*width+x]
and reads past raw -- an out-of-bounds write / NULL-page store and crash.

Reject zero/degenerate dimensions and use hb_unsigned_mul_overflows()
for both (width + 1) * height and width * height before allocating,
sizing the inflate, and indexing.  This bounds every subsequent
raw + y*(width+1) and out->arrayZ[y*width+x] access.

Add a CBDT regression seed embedding a 65536x65536 indexed PNG with a
tRNS chunk; it reaches the soft-mask builder through
hb_font_paint_glyph -> CBDT::paint_glyph -> hb_pdf_paint_image and
crashed pre-fix under ASAN/UBSan at hb-vector-paint-pdf.cc:617.

Fixes: GHSA-gmjm-qc3c-qfp8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 00:16:00 -06:00
Behdad EsfahbodandClaude Opus 4.8 9a55008395 [vector-pdf] Fix PLTE chunk-length wrapping OOB read in PNG parser
The PNG chunk-bounds check in hb_pdf_paint_image() used wrapping
32-bit unsigned arithmetic:

    if (pos + 12 + chunk_len > len)
      break;

A large attacker-controlled chunk_len (e.g. 0xFFFFFF30) wraps
pos + 12 + chunk_len below len, so a truncated PLTE chunk passes the
check.  The oversized plte_len is then trusted during palette
serialization in add_xobject_png_image(), reading far past the input
buffer -- an out-of-bounds read and deterministic crash.

Rewrite the bounds checks to be non-wrapping, relying on the invariant
pos <= len (len >= 8 is checked earlier): gate the loop on
len - pos >= 12 and reject a chunk with chunk_len > len - pos - 12.
This keeps pos <= len across pos += 12 + chunk_len and makes every
in-loop read (chunk header and chunk payload) provably in bounds.

Add a regression seed font that embeds a malformed indexed PNG with an
oversized PLTE length via sbix.  It reaches the vector-PDF paint path
through hb_font_paint_glyph -> sbix::paint_glyph -> hb_pdf_paint_image
and crashed pre-fix under ASAN at hb-vector-paint-pdf.cc:222; it now
renders cleanly.

Fixes: GHSA-9m78-3jcg-57f2
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 00:08:05 -06:00
Behdad Esfahbod 760470e91e [raster] Avoid clip mask origin overflow (#6044)
Clip mask extents can have extreme signed origins after malformed
or heavily transformed outlines. Subtracting the surface origin in
int overflowed for cases such as 0 - INT_MIN.

Keep the mask-to-surface coordinate conversion in int64_t until
after intersecting with the finite clip and surface bounds, then
convert to unsigned only for proven in-range pixels.

Add the minimized OSS-Fuzz seed to the raster fuzzer corpus.

Testing: meson test -C build
Fixes: https://oss-fuzz.com/testcase-detail/4621471331450880
Assisted-by: OpenAI Codex <codex@openai.com>
2026-06-29 15:26:24 -06:00
Skef Iterum d6ff01763f [depend] Filter out-of-range GIDs from parity checker starting set
hb_font_get_nominal_glyph can return GIDs >= num_glyphs for
malformed cmap format 4 tables.  The subsetter's plan creation
filters these via _remove_invalid_gids, but the parity checker's
codepoint-to-glyph mapping did not.  This caused spurious
over-approximation on AOTS cmap4 test fonts.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef Iterum ea668aaa34 [depend] Detect GSUB self-feeding chains in parity checker
When the parity checker finds unexpected over-approximation (depend
closure has extra glyphs without flagged edges), check whether the
font has self-feeding GSUB lookups — lookups whose output coverage
overlaps their input coverage.  These create transitive chains that
the depend closure follows to completion while the subsetter's
iteration-capped closure truncates.

No shaper re-applies a lookup to its own output within a single
feature application, so the extra glyphs are harmless.  The
detection traces extra glyphs through self-feeding feature edges
from the subset closure; if all are explained, the test passes.

Detection runs only on the failure path and is O(edges), so
well-formed fonts (which don't have self-feeding lookups) pay no
cost.

Also document MATH single-pass closure and GSUB self-feeding chains
in depend-for-closure.md and depend-implementation.md.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 075535160c [depend] Group test-generation utilities by purpose with section headers
Split the former "test generation infrastructure" section into three
labelled subsections:

  - Random sampling utilities  (rng_range / rng_select_distinct / rng_select_from_set)
  - Font and input queries     (get_gsub_features / parse_unicodes / parse_gids / parse_features)
  - Test parameter generation  (test_params / generate_test_from_explicit / generate_test_from_seed)

get_gsub_features was previously stranded between the RNG helpers and the
parsers; the new header makes clear it belongs with the input queries.
No logic changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 d00f8a7b64 [depend] Reorder hb-depend-closure-parity.cc for narrative clarity
Reorder the file so a reader encounters code in the order they need to
understand it:

  1. Overview comment explaining the two-closure comparison approach
  2. Configuration globals and init_parity_config()
  3. Closure algorithm (depend side): deferred_ligature_t, depend_closure_ctx_t,
     check_context_satisfied, process_edges_for_tables, compute_depend_closure
  4. Closure algorithm (subset side): compute_subset_closure
  5. Comparison and reporting: print_test_params, compare_closures
  6. Test generation infrastructure: rng helpers, get_gsub_features,
     parse_unicodes/gids/features, test_params, generate_test_from_*
  7. LLVMFuzzerTestOneInput

Previously the test generation infrastructure (hundreds of lines of seed and
parser code) appeared before the parity checking logic, forcing a reader to
hold a lot of context before seeing what the file was for.  The forward
declaration of get_gsub_features() is also removed since it now precedes
parse_features().  No logic changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 adf1f8e7c5 [depend] Refactor hb-depend-closure-parity.cc for readability
- Add `rng_prob_hit()` helper to replace three repeated injection-check
  patterns, each of which was 4–6 lines of std::uniform_real_distribution
  boilerplate.
- Add `depend_closure_ctx_t` struct to group the parameters that were
  threaded individually through `process_edges_for_tables` (10 params)
  and `compute_depend_closure` (9 params); both now take 2–3 params.
- Remove dead `vs_to_gid` map that was created, passed through three
  call layers, and never read.
- Fix GSUB-stage indentation in `compute_depend_closure`: the old code
  had a spurious outer `{ }` block containing all five table stages,
  with the `if (!skip_gsub)` body indented at the wrong level.
- Move `ligature_set_glyphs` into the GSUB stage block where it belongs.

No behaviour change; all tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 0cf8d384b5 [depend] Address review feedback: typedef depend contexts, fix fuzzer font set
- ContextDependLookupContext / ChainContextDependLookupContext: replace
  duplicate struct definitions with typedefs of their Closure counterparts,
  removing the now-unnecessary reinterpret_casts and layout-identity comments
- test/fuzzing/meson.build: switch depend-closure-parity from api_fonts_glob
  to subset_fonts_glob; remove api_fonts_glob (the fuzzer produces malformed
  fonts anyway, per behdad review)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 ea0b0767e7 [depend] Change hb_subset_depend_lookup_glyph to array-getter pattern
Follows HarfBuzz convention: return total count, take start_offset +
entry_count IN/OUT + entries array. This allows callers to query the
total without filling, page through entries, or fetch all at once.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 6a5f32c505 [depend] Public API overhaul: rename to hb_subset_depend_*, struct fill, remove print
- Rename all public symbols hb_depend_* → hb_subset_depend_*
- Rename hb_depend_t → hb_subset_depend_t
- Replace get_glyph_entry (multi out-param) with lookup_glyph (fills
  hb_subset_depend_entry_t struct; fields use ligature_set_index /
  context_set_index)
- Rename get_set_from_index → lookup_set
- Remove hb_depend_print from public API (util/hb-subset-depend TODO)
- Move hb_subset_depend_edge_flags_t to hb-depend.h; apply
  HB_MARK_AS_FLAG_T in hb-depend-data.hh (internal header only, since
  hb-algs.hh is not available in public headers)
- Rename HB_DEPEND_EDGE_FLAG_* → HB_SUBSET_DEPEND_EDGE_FLAG_*
- Update gen-def.py, check-symbols.py, and all test callers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 9a5d99f850 [depend] Address review feedback: preprocessor guards, minor API and naming fixes
Replace HB_DEPEND_API with HB_NO_SUBSET_DEPEND gated on HB_EXPERIMENTAL_API
and HB_LEAN in hb-config.hh, with HB_SUBSET_DEPEND_API opt-in to allow
enabling without full experimental API. Remove depend_api meson option;
depend tests now build under experimental_api=true. Fold depend symbols into
experimental symbols in gen-def.py.

Internal fixes: use free_set_list.pop(), push_or_fail() for allocation safety,
return const hb_set_t* from internal get_set_from_index. Ligature.hh: use
hb_sink iterator, rename ligset→ligset_idx, source→gid. Remove stale
test_depend_cmap unit test (cmap extraction was removed in d4d4c635).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude edc3a6fa9a [test] Improve error message for missing font files in parity checker
Replace bare assert(blob) with a proper error message when
hb_blob_create_from_file_or_fail returns NULL. This gives users
a clear indication of which file couldn't be loaded instead of
a cryptic assertion failure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.5 913d3c54ce Handle UVS closure separately from depend graph
UVS (Unicode Variation Sequence) edges in the depend graph couldn't
properly represent the filtering requirement that BOTH the base unicode
AND variation selector must be in the input unicodes. This caused
over-approximation in depend closure vs subset closure.

Solution: Handle UVS separately using existing query APIs
- Skip all cmap edges during depend closure processing
- Use hb_font_get_variation_glyph() to query UVS mappings directly
- For GSUB tests: Use input codepoints directly for UVS queries
- For non-GSUB tests: Build unicodes from starting glyphs via forward
  cmap iteration (hb_face_collect_nominal_glyph_mapping)

This correctly matches subset's UVS handling while keeping the depend
graph focused on non-UVS dependencies.

Also fixes -t parameter to support full 64-bit test seeds by parsing
as string before converting to uint64_t.

Test results:
- NotoSansMath-Regular.ttf: 100,000 tests pass
- Padauk-Bold.ttf: 100,000 tests pass
- ReemKufiInk-Regular.ttf: 100,000 tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00