Commit Graph
269 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 d134f88824 [vector] Fix clear() when vector is in error state
clear() called resize(0) which calls alloc(0), but alloc() bails
immediately when the vector is in error state, so length was never
zeroed. Under failing-malloc, a vector could enter error state from
a failed push, making all subsequent clear() calls silently fail,
leaving stale pointers.

This caused a heap-use-after-free in hb_raster_paint_destroy():
render() released surfaces to surface_cache then called
surface_stack.clear() which silently failed, so destroy() iterated
the stale surface_stack pointers and double-freed images already
in surface_cache.

Fixes https://oss-fuzz.com/testcase?key=5078588000108544

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:26:18 -06:00
Behdad Esfahbod 074b6c826a Add a fuzzer test 2026-03-20 17:50:08 -06:00
Behdad Esfahbod be6fca21f5 [vector] Fail closed on SVG paint body OOM
The SVG paint backend could keep going after failing-malloc
poisoned the root or nested group body buffers. In particular,
hb_vector_paint_ensure_initialized() only checked group_stack
itself, not the allocated root body, and some group and glyph
paths ignored push_or_fail() or append-induced vector error
state.

Treat an errored root body as initialization failure, reject
cached and non-cached glyph emission when defs, current body,
or captured scratch enter error state, and stop ignoring
nested group push failure.

Testing: CCACHE_DISABLE=1 meson test -C build-codex

Fixes: https://oss-fuzz.com/testcase-detail/4521131913838592
Assisted-by: OpenAI Codex
2026-03-19 09:55:24 -06:00
Behdad Esfahbod 6af602fa64 Add a fuzzer font 2026-03-19 09:47:44 -06:00
Behdad Esfahbod c89f1c20b0 [raster] Harden color-stop fetches under failing malloc (#5858)
Malformed COLRv1 gradients can report a non-zero stop count and then
leave the effective stop array empty once allocations fail. The raster
path assumed the second fetch always produced at least one stop and
indexed stops[0], which let fuzzing hit a stack-buffer-underflow in
evaluate_color_line().

Reject empty effective stop lists after the second fetch, handle
zero-stop and one-stop evaluation defensively, and clamp non-finite
gradient parameters before lookup. Apply the same stop-fetch
hardening to the Cairo and vector paint helpers, including fixing
Cairos wrong NULL check after hb_malloc().

Testing: not run (per user request)

Fixes: https://oss-fuzz.com/testcase-detail/4635834988167168
Assisted-by: OpenAI Codex
2026-03-18 16:06:29 -06:00
Behdad Esfahbod 4462e9862d [vector][colr] Guard color_glyph reentry in SVG paint backend
The vector color_glyph callback can re-enter painting through
PaintColrGlyph, creating an unbounded callback recursion path that does
not consume COLR paint-context depth counters.

Track active color glyphs to reject immediate/indirect cycles and add a
hard nested callback depth cap based on HB_MAX_NESTING_LEVEL.

Tested:
- CCACHE_DISABLE=1 ninja -C /home/behdad/harfbuzz/build-codex test/fuzzing/hb-vector-fuzzer
- for f in test/fuzzing/fonts/crash-* test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-*; do ./build-codex/test/fuzzing/hb-vector-fuzzer "$f"; done

Fixes: https://oss-fuzz.com/testcase-detail/5985308075425792
Assisted-by: OpenAI Codex
2026-03-17 09:39:46 -06:00
Behdad Esfahbod df9b6ff641 [vector][colr] Sanitize ColorLine extend values
COLR ColorLine::get_extend() cast the raw Extend byte directly to
hb_paint_extend_t. Malformed tables can carry out-of-range values,
which then trip UBSan enum checks in vector paint paths.

Map raw extend values explicitly and fall back to PAD for unknown
values.

Tested:
- CCACHE_DISABLE=1 ninja -C /home/behdad/harfbuzz/build-codex test/fuzzing/hb-vector-fuzzer test/fuzzing/hb-raster-fuzzer
- ./build-codex/test/fuzzing/hb-vector-fuzzer test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-5448347908636672
- ./build-codex/test/fuzzing/hb-vector-fuzzer test/fuzzing/fonts/NotoColorEmoji.subset.ttf

Fixes: https://oss-fuzz.com/testcase-detail/6120408016551936
Assisted-by: OpenAI Codex
2026-03-17 09:33:31 -06:00
Behdad Esfahbod acc0a54ddc [raster] Remove remaining signed-shift UB in edge stepping
Raster edge setup still had signed-shift UB in two places:
- slope scaling in emit_segment() when dx is negative
- x-boundary stepping in edge_sweep_row() when cx0 is negative

Compute slope with widened subtraction and multiplication, and compute
x_b using widened multiply plus clamp.

Tested:
- ./build-codex/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/crash-d223bc42a8226c4d655c417d63d9a76760d05985
- ./build-codex/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6454028543524864

Assisted-by: OpenAI Codex
2026-03-17 09:27:48 -06:00
Behdad Esfahbod bdbf83e26d [raster] Avoid signed-shift UB in scanline y conversion
hb_raster_draw_render() computed y_top by left-shifting a signed value
that can be negative when extents have a negative y origin.

Switch to 64-bit multiplication by HB_RASTER_ONE_PIXEL and clamp to
int32_t range before use, preserving behavior without signed-shift UB.

Tested:
- CCACHE_DISABLE=1 ninja -C /home/behdad/harfbuzz/build-codex test/fuzzing/hb-raster-fuzzer
- ./build-codex/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6454028543524864

Fixes: https://oss-fuzz.com/testcase-detail/6454028543524864
Assisted-by: OpenAI Codex
2026-03-17 09:19:07 -06:00
Behdad Esfahbod ba53130d2c [vector][svg] Harden subset spans under failing-malloc
Validate cached SVG spans before use and make cache parsing
allocation-failure safe.

Fixes: https://oss-fuzz.com/testcase-detail/5448347908636672
Assisted-by: OpenAI Codex
2026-03-17 09:12:35 -06:00
Behdad Esfahbod 6815666a74 [raster] Preserve base transform on failed pushes
The raster backend lets push_transform() fail under the fuzzing failing-
allocator path, but pop_transform() always removed the current stack
entry. That can discard the base transform when a nested push did not
actually land, corrupting subsequent raster operations.

Guard pop_transform() so it only removes nested transforms and preserves
the base transform frame.

Tested:
- meson compile -C build hb-raster-fuzzer

Speculative fix for: https://oss-fuzz.com/testcase-detail/4743569679384576
Assisted-by: OpenAI Codex
2026-03-14 13:29:51 -03:00
Behdad Esfahbod 03006b06ba [raster] Avoid signed-shift UB in edge slope setup
emit_segment() formed its 16.16 fixed-point slope by left-shifting a
signed delta-x value. Negative dx values make that shift undefined, and
UBSan reports it on malformed glyph outlines.

Use 64-bit multiplication by 1<<16 instead, preserving the same fixed-
point result without relying on signed-shift behavior.

Tested:
- meson compile -C build hb-raster-fuzzer

Fixes: https://oss-fuzz.com/testcase-detail/4797078076456960
Assisted-by: OpenAI Codex
2026-03-14 13:22:56 -03:00
Behdad Esfahbod cb0757aad9 [raster] Reject empty gradient stop lists
The raster gradient code assumed every color line had at least one stop.
Malformed COLR data can report an empty stop list, which then reaches
normalize_color_line() and evaluate_color_line() and reads stops[0].

Treat empty color lines as a failed gradient fetch so malformed inputs
render nothing instead of dereferencing past the stop array.

Tested:
- meson compile -C build hb-raster-fuzzer

Fixes: https://oss-fuzz.com/testcase-detail/5216672087867392
Assisted-by: OpenAI Codex
2026-03-14 13:19:29 -03:00
Behdad Esfahbod ef191e9b2c [raster] Guard SVG stack pops on allocation failure
The raster SVG renderer assumed push_group() and push_transform()
always succeeded. Under the fuzzing failing-allocator path those pushes
can fail, but the matching pops still ran unconditionally.

When SVG rendering is nested inside an existing paint operation, an
unmatched pop can remove the caller's transform or group and later trip
the stack-balance assertions.

Track whether each raster SVG push actually grew the corresponding stack
and only pop in that case.

Tested:
- meson compile -C build hb-raster-fuzzer
- build/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/NotoColorEmoji.subset.ttf

Fixes: https://oss-fuzz.com/testcase-detail/5627961964560384
Assisted-by: OpenAI Codex
2026-03-14 13:17:05 -03:00
Behdad Esfahbod c197509b4b [vector] Avoid stale SVG paint body references (#5843)
The non-cached SVG paint path kept a reference to the current group
body across hb_font_paint_glyph_or_fail(). Nested paint groups can
grow group_stack and move its storage, leaving that reference dangling.

Append to current_body() directly before and after the recursive
paint call so the code never reuses a body reference after the stack
may have reallocated.

Fixes: https://oss-fuzz.com/testcase-detail/5622008821121024
Testing: meson test -C build
Assisted-by: OpenAI Codex
2026-03-13 14:32:22 -06:00
Garret Rieger 51b9d2c756 Add fuzzer seed for malformed axis ranges. 2026-03-10 11:58:52 -06:00
Behdad Esfahbod a4ce5caeea Add handwriting fuzzer text trailers 2026-03-10 01:38:06 -03:00
Behdad Esfahbod acdf518d42 [fuzzing] Add noto handwriting color fonts
From https://github.com/googlefonts/color-fonts
2026-03-09 23:00:03 -03:00
Behdad Esfahbod 6913fd88b8 [fuzzing] Add --downgrade-cff seed using new facilities 2026-03-04 14:07:08 -03:00
Behdad Esfahbod 7672d6bd52 [fuzzing] Add test for --downgrade-cff 2026-03-04 13:58:38 -03:00
Qunxin Liu 7ed158f930 Fix fuzzer issue (#5741)
Fixes: https://oss-fuzz.com/testcase-detail/6406793692774400
2026-02-11 13:12:30 -07:00
Qunxin Liu e601560b77 fix fuzzer issue: https://oss-fuzz.com/testcase-detail/6005602106277888
Do not use pointers that may point outside of the allocated memory region
2026-01-23 11:44:39 -07:00
Behdad Esfahbod dc73849f56 [gvar] Fix padding size calcs (#5718)
The previous state of is_long_offset() is irrelevant here.

Fixes https://oss-fuzz.com/testcase-detail/5920156651159552
2026-01-22 18:08:51 -07:00
Qunxin Liu b17fa8ef39 Fix fuzzer found heap-use-after-free crash (#5717)
Fixes https://oss-fuzz.com/testcase-detail/6005602106277888
2026-01-21 14:42:29 -07:00
Garret Rieger 09c14fa4f2 Fix fuzzer found memory leak. (#5643)
Fixes https://oss-fuzz.com/testcase-detail/6083012753424384
2025-11-14 02:27:35 -07:00
Behdad Esfahbod 844f2fea06 [GPOS] Handle attach_chain() overflow (#5636)
Fixes https://oss-fuzz.com/testcase-detail/5461871294742528
2025-11-03 20:28:54 -07:00
Behdad Esfahbod f159600ccb Fix a draw fuzzer uninitialized-memory issue (#5615)
Fixes https://oss-fuzz.com/testcase-detail/5714890590584832
2025-10-17 19:49:40 -06:00
Behdad Esfahbod a89c36e0d9 [GPOS/kerx] Support attaching marks to bases after them (#5520)
See comments. Fuzzer found. I'm surprised this was not discovered
before though. I hope I have not missed anything.

Fixes https://oss-fuzz.com/testcase-detail/6399443634290688
2025-09-02 13:05:11 -06:00
Garret Rieger 04d60de6ae [CFF2] Fix fuzzer failure in CFF2.
Fixes https://oss-fuzz.com/testcase-detail/5291661985120256
2025-07-23 12:59:22 -06:00
Garret Rieger 0660a4d408 [subset] fix fuzzer found heap use after free in BASE subsetting. 2024-05-13 13:39:20 -07:00
Behdad Esfahbod ba1f194a1d [gsubgpos] Reduce stack use in recursion 2024-05-02 16:37:51 -05:00
Garret Rieger c84acc8e07 [subset] Fix fuzzer found memory leak.
Fixes https://oss-fuzz.com/testcase-detail/6159925345583104.
2024-04-09 08:41:32 -05:00
Garret Rieger ef1f5c4e0c [subset] Re-use common Coverage subsetting function in PairPosFormat2.
Was using an identical but less efficient version. Fixes fuzzer test case: https://oss-fuzz.com/testcase-detail/6151390002806784
2024-01-08 15:34:45 -07:00
Garret Rieger 333946b00e [subset] Fix fuzzer timeout.
Fixes https://oss-fuzz.com/testcase-detail/5458896606855168. Limit iteration over coverage in MarkLigPosFormat1 subsetting to the number of glyphs in the liga array.
2023-09-28 14:22:51 -06:00
Qunxin Liu 9ceb800ac2 fuzzer fix https://oss-fuzz.com/testcase-detail/5842152921628672
Access TupleVariationData through blob, because we don't sanitize
var_data
2023-09-28 12:51:44 -06:00
Qunxin Liu fd3eb2c672 fuzzer fix: https://oss-fuzz.com/testcase-detail/6032126569742336 2023-09-05 21:51:02 +03:00
Garret Rieger a1f034eaac [repacker] fix fuzzer failure.
Fixes: https://oss-fuzz.com/testcase-detail/6490945267564544
2023-08-28 23:17:13 -04:00
Garret Rieger ca906e8747 [repacker] fix fuzzer timeout.
Corrects some mistakes in the handling of incoming_edges_ when memory allocation failures happen.
2023-08-17 12:01:44 -06:00
Behdad Esfahbod 94d4283b12 [graph] Handle a malloc fail
Fixes https://oss-fuzz.com/testcase-detail/4579249263345664
2023-08-01 15:06:01 -06:00
Behdad Esfahbod 997986ab30 [subset/hvar] Error handling
Fixes https://oss-fuzz.com/testcase-detail/5029952234586112
2023-07-09 15:16:06 -06:00
Behdad Esfahbod f60dbd906a Fix thinko
Fixes https://oss-fuzz.com/testcase-detail/4787105656864768
2023-07-08 16:21:24 -06:00
Behdad Esfahbod 25297408de [COLR] Fix PaintComposite sanitize timeout
Was timing out after recent sanitize() change.

Fixes https://oss-fuzz.com/testcase-detail/5692635449524224
2023-07-03 10:35:27 -06:00
Behdad Esfahbod 0cf759b0d4 [Glyph] Don't shift anchored Composite if phantom_only
Fixes https://oss-fuzz.com/testcase-detail/5114131137822720
2023-07-02 12:15:43 -06:00
Behdad Esfahbod cc44b3bce0 [subset/cff1] Handle an error condition
Fixes https://oss-fuzz.com/testcase-detail/5191907895279616
2023-06-29 16:13:19 -06:00
Behdad Esfahbod 62f5ed461e [subset/cff] Fix an infinite loop
Fixes https://oss-fuzz.com/testcase-detail/5419002026131456
2023-06-28 12:04:28 -06:00
Behdad Esfahbod 347b944811 [null] Fix getting Crap(hb_bytes_t)
Fixes https://oss-fuzz.com/testcase-detail/6187272924692480
2023-06-26 18:10:36 -06:00
Behdad Esfahbod 6c4f975dcb Add a fuzzer font 2023-06-25 23:37:08 -06:00
Garret Rieger db700b5670 [subset] fix fuzzer timeout.
Fixes: https://oss-fuzz.com/testcase-detail/6681253479579648. Limits iteration of coverage table during MATH subset to valid glyphs.
2023-06-13 08:42:36 -06:00
Behdad Esfahbod 2e6919d526 [subset/cff2] Error handling
Fixes https://oss-fuzz.com/testcase-detail/4916785942757376
2023-06-10 10:08:56 -06:00
Behdad Esfahbod d08aee5a7e Add fuzzing test 2023-06-08 13:20:28 -06:00