The shader source is compatible with both GLSL 3.30 and
GLSL ES 3.00. Rename the enum value to reflect this and
match the type name convention.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The leading-comment mechanism corrupted fuzzer font files by
prepending non-font data. Remove the function, its callers,
and strip the one seed file that had a leading comment.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shaping is already exercised by the shape fuzzer. Simplify
the raster and vector fuzzers to just render gids 0..15
directly, matching the GPU fuzzer pattern.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Change hb_gpu_shader_{fragment,vertex}_sources() (array + count)
to hb_gpu_shader_{fragment,vertex}_source() returning a single
const char *. Each language variant is one complete string.
Simplifies the demo shader compilation and documentation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Encodes up to 16 glyphs per fuzzed font input, exercising
draw accumulation, cu2qu, encode, extents, and blob recycling.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The raster SVG image callback assumes hb_raster_paint_glyph()
seeded svg_font/svg_glyph state before the paint protocol
reaches HB_PAINT_IMAGE_FORMAT_SVG. Clients can also call
hb_font_paint_glyph_or_fail() directly with
hb_raster_paint_get_funcs(), which leaves svg_font unset and
crashes in hb_raster_svg_render().
Return false when the callback is reached without that
wrapper-only state, and cover the direct API path with a
regression test.
Testing: CCACHE_DISABLE=1 meson test -C build
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-ggh9-cgg2-r4vr
Assisted-by: OpenAI Codex <codex@openai.com>
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>
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
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
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
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
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
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
Avoid abort/assert in renormalizeValue when avar triples are malformed
and guard zero-distance divisions.
Add a regression case in test-subset-instancer-solver and include the
OSS-Fuzz reproducer file.
Fixes: https://oss-fuzz.com/testcase-detail/6461128124465152
Assisted-by: OpenAI Codex
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
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
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
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
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
Extend the vector regression tests to cover the remaining handwriting
fuzzing fonts: sbix, glyf COLRv1, and CFF/CFF2 COLRv1.
Reuse the expected output where the CFF and CFF2 variants serialize
identically.
Assisted-by: OpenAI Codex
Some SVG glyph documents reuse the same referenced element multiple
times. The vector subsetter treated a duplicate ref as a hard failure,
which made hb-vector drop glyphs like U+270D from the handwriting
picosvg test fonts entirely.
Treat duplicate and empty refs as non-fatal while still uniquing the
collected ids. Add regressions for the handwriting picosvg and picosvgz
fonts, reusing a shared expected output for the pair.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/5829
Assisted-by: OpenAI Codex
Vector SVG extraction still treated SVG table documents as plain text,
so svgz payloads worked in raster but failed in hb-vector.
Move the gzip helpers into a new internal hb-zlib.hh header and add a
shared SVG blob normalization helper in svg.hh. Raster and vector now
both normalize SVG documents before doc-cache or rendering/subsetting
logic sees them, with the same 16 MiB uncompressed size limit.
Also link zlib into harfbuzz-vector when available and add a vector
regression that checks matching output for the existing plain and
compressed handwriting SVG fonts.
Tested:
- meson test -C build
Assisted-by: OpenAI Codex
The raster SVG path treated hb_ot_color_glyph_reference_svg()
blobs as plain XML, even though SVG table documents may
legally be gzip encoded. That caused hb-raster to reject
fonts that store compressed SVG documents.
Detect gzip payloads in the raster SVG renderer, reject
documents whose advertised uncompressed size exceeds
HB_SVG_MAX_DOCUMENT_SIZE, and inflate the rest through
zlib while keeping the same size cap enforced during
decompression. Plain SVG documents are also bounded by the
same 16 MiB limit.
Add a raster API regression that renders the existing
plain and compressed noto_handwriting SVG fixtures and
verifies identical output.
Testing:
- meson test -C build
Assisted-by: OpenAI Codex
The raster and vector fuzzers called create_or_fail() and then
immediately dereferenced the returned pointers. Under CIFuzz's
allocation-failure coverage, that turns a valid NULL return into a
harness crash instead of treating it as an out-of-memory case.
Return early after cleaning up when draw or paint context creation
fails. This keeps the fuzzers aligned with the create_or_fail()
contract and avoids null-deref crashes unrelated to library logic.
Tested:
- meson compile -C build hb-raster-fuzzer hb-vector-fuzzer
- build/test/fuzzing/hb-vector-fuzzer test/fuzzing/fonts/TwemojiMozilla.subset.ttf
- build/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/TwemojiMozilla.subset.ttf
Assisted-by: OpenAI Codex
Skip the SVG table accelerator and do not define the public
SVG color APIs when HB_NO_SVG is set. Guard internal
callers so SVG-table-dependent code compiles out cleanly,
and add HB_NO_SVG to the HB_TINY profile.
Tested: meson setup build-nosvg -Dc_args=-DHB_NO_SVG -Dcpp_args=-DHB_NO_SVG
Tested: meson compile -C build-nosvg hb-shape hb-info hb-vector main
Tested: meson compile -C build-nosvg (libharfbuzz/libharfbuzz-raster/libharfbuzz-vector linked; full tree stopped on unrelated missing chafa.h in util/hb-raster.cc)
Tested: nm -gU build-nosvg/src/libharfbuzz.0.dylib | grep -E "hb_ot_color_.*svg" (no matches)
Assisted-by: OpenAI Codex
reinterpret_cast<const instructions_t &>(data) reads the bytes of the
pointer variable itself (stack address, determined by ASLR), not the
fuzzer input buffer. This makes operation and first_set_size effectively
uncontrollable by the fuzzer.
Fix by dereferencing: reinterpret_cast<const instructions_t &>(*data)
This also removes the #pragma suppressing -Wstrict-aliasing, which was
warning about exactly this problem.
Coverage comparison (10-min libFuzzer run):
- Original: 15 lines (0.05%), 2 functions
- Fixed: 486 lines (1.47%), 144 functions (29x improvement)