These are convenience APIs, not typesetting APIs — positioning
is the caller's responsibility via set_transform(). This
matches the GPU API which never had pen parameters.
All callers updated to use set_transform with pen position
before each _glyph call.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Malicious fonts with extreme scale values cause huge pixel
buffer allocations across multiple push_group surfaces. The
library correctly bounds individual surfaces at 1 GB, but
stacked group surfaces can exceed the fuzzer RSS limit.
Cap the font scale to 1000 in the harness so the exercised
surface stays within fuzzer memory constraints.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When clip nesting exceeds HB_GPU_PAINT_MAX_CLIP_DEPTH (3),
push_clip_glyph sets unsupported=true but still increments
clip_depth. emit_all_clip_sub_blobs then iterated clip_depth
without capping, reading past the fixed-size clip_stack array.
Cap the iteration at HB_GPU_PAINT_MAX_CLIP_DEPTH.
Fixes: https://oss-fuzz.com/testcase-detail/6573156621156352
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Flat mode disabled glyph reuse / caching to produce inline-
everything SVG output. Its main use case was making
hb-vector SVGs safe to concatenate side-by-side in a single
document, but the recently-added svg_set_prefix API solves
that without giving up the cache. No remaining callers in
tree (util/vector-output.hh's --flat option goes too).
Removes:
- hb_vector_draw_set_flat / get_flat
- hb_vector_paint_set_flat / get_flat
- the `flat` field on both contexts
- all `if (flat)` / `bool can_cache = !flat` branches
- the --flat option in util/vector-output.hh
- the four "flat*" expected files in test/vector/basic
- the flat_draw / flat_paint params in the vector fuzzer
- sections-list entries
meson test --no-rebuild green (241/241).
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three accumulator vectors -- ops, sub_blobs, transform_stack --
can enter error state via failed push_or_fail() under
failing-malloc. Once in error state, resize(0) short-circuits
at the in_error() guard in alloc() and leaves length unchanged.
In hb_gpu_paint_clear that means the next iteration's clear
walks the stale entries again. For sub_blobs this is a
double-destroy: the blob pointers were already freed in the
previous clear, and hb_blob_destroy reads the dead ref_count
field -- heap-use-after-free.
Fix by calling vector.reset(), which clears the error state
before resizing to 0. Matches the pattern hb_gpu_draw_clear
already uses for draw->curves.
Found by oss-fuzz/CIFuzz on hb-gpu-fuzzer; minimized testcase
added to the fuzz corpus.
Assisted-by: Claude <noreply@anthropic.com>
Two sites queried color-stop count, resized the scratch vector to
match, then called hb_color_line_get_color_stops() passing the
requested count as the write capacity. If the resize() failed
(OOM), the vector stayed at its previous (smaller) length while
the callee still wrote the full requested count -- heap-buffer-
overflow.
Fixed by checking resize() and bailing: build_gradient_function
returns 0, paint_sweep_gradient returns. Matches the pattern
already used in hb-raster-paint.cc and hb-vector-paint.cc.
Found by oss-fuzz/CIFuzz on hb-vector-fuzzer against a sweep-
gradient COLRv1 glyph under failing-malloc.
Assisted-by: Claude <noreply@anthropic.com>
The existing hb-gpu-fuzzer only exercised hb_gpu_draw. Add a
parallel paint round-trip per glyph (paint_glyph -> encode ->
recycle_blob) so the paint encoder gets the same fuzzed-input
coverage -- gradient / transform / composite parsing in
particular has a lot more surface than the slug encoder.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_raster_paint_glyph() took the palette index and foreground
color as per-call arguments, duplicating state that also lives on
the paint context (foreground via hb_raster_paint_set_foreground,
palette previously only available as a per-call arg). This gave
callers two paths for configuring the same state.
Drop the per-call palette/foreground arguments and require callers
to configure them via setters before painting, matching the
already-established pattern in hb_vector_paint_glyph() and
elsewhere in the subsystem.
- Drop palette and foreground args from hb_raster_paint_glyph().
- Add hb_raster_paint_set_palette() / _get_palette() and a
hb_raster_paint_get_foreground() companion.
- Store palette on hb_raster_paint_t (default 0).
- Update util/raster-output.hh, util/hb-raster-all.cc, and
test/fuzzing/hb-raster-fuzzer.cc to the new API.
- Update the hb-raster section-doc example.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously only HB_VECTOR_FORMAT_SVG was fuzzed. Factor the
create/paint/render body into a helper and call it twice per
input — once for SVG, once for PDF — so the PDF-specific code
paths get the same coverage:
- PDF content-stream encoder
- Type 2/3 shading + stitching function builder
- Type 6 Coons-patch sweep gradient encoder (hb_pdf_add_sweep_patch)
- PNG IDAT passthrough
- Indexed-PNG SMask builder (hb_pdf_build_indexed_smask, zlib inflate
+ PNG un-filter + palette-to-alpha mapping)
Input-fuzzed knobs (precision, flat-draw, flat-paint) are shared
between the two formats.
Smoke-tested on a handful of existing fuzzing/fonts corpus entries;
all pass clean.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bring hb_gpu_draw_encode into line with the rest of the render APIs:
auto-clear on success, and return the computed glyph extents to the
caller via a new out-parameter (nullable).
HB_EXTERN hb_blob_t *
hb_gpu_draw_encode (hb_gpu_draw_t *draw,
hb_glyph_extents_t *extents);
Consumers typically need both the encoded blob and the glyph's
extents to size the quad they'll draw into in the vertex shader;
returning them together removes a redundant trip through the draw
state and lets encode() auto-clear like hb_vector_*_render() and
hb_raster_*_render() do.
Drop hb_gpu_draw_get_extents() from the public API — its only
role was reading extents out of the draw state post-encode, which
the new encode() signature makes redundant. The computation
stays (moved to a static _hb_gpu_draw_get_extents helper) so
encode() can call it before auto-clear wipes the state.
ABI break for anyone who had already wired up against the 14.0.0
hb_gpu_draw_encode signature or hb_gpu_draw_get_extents, but the
library is new/experimental and the two in-tree consumers
(test/api/test-gpu.cc, util/gpu/demo-font.cc, util/hb-gpu-encode-all.cc,
test/fuzzing/hb-gpu-fuzzer.cc) are updated here.
All 240 tests pass.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Drop "svg" from the names since flat/precision settings apply
equally to PDF output. The new names follow the hb_vector_draw_*
/ hb_vector_paint_* convention:
hb_vector_svg_set_flat -> hb_vector_draw_set_flat
hb_vector_svg_set_precision -> hb_vector_draw_set_precision
hb_vector_svg_paint_set_flat -> hb_vector_paint_set_flat
hb_vector_svg_paint_set_precision -> hb_vector_paint_set_precision
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_extents_t::to_glyph_extents() rounded bounds to hb_position_t
before subtracting them. Extreme extents from fuzzed VARC and
raster paths could therefore overflow signed int arithmetic while
forming glyph widths or heights.
Compute the rounded endpoints in double, clamp the exported values
to hb_position_t, and reject non-finite results. Also avoid the
same overflow in the reverse hb_glyph_extents_t constructor, add
an internal regression for the shared helper, and include the
minimized raster testcase.
Fixes: https://oss-fuzz.com/testcase-detail/4826864710647808
Not-tested: Skipped by request.
Assisted-by: OpenAI Codex
hb_gpu_draw_get_extents() cast rounded bounds to hb_position_t
before subtracting them. A fuzzed glyph outline with an extreme
negative bound could therefore overflow signed int arithmetic while
forming width or height.
Compute the rounded bounds in double, reject non-finite values, and
clamp the exported extents to hb_position_t before returning them.
Add an API regression that covers the OSS-Fuzz testcase through the
public GPU draw API.
Fixes: https://oss-fuzz.com/testcase-detail/5918954634936320
Tested: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
Malformed reflected gradients can produce very large finite
gradient parameters. The raster backend normalized reflect
mode by casting floorf(t) to int, which can overflow and
drive LUT lookups past the fixed-size stack buffer.
Fold reflected coordinates with fmodf(), clamp LUT inputs
defensively, and add the minimized oss-fuzz raster
testcase to the corpus.
Fixes: https://oss-fuzz.com/testcase-detail/6597066439852032
Tested: meson test -C build
Co-Authored-By: OpenAI Codex <codex@openai.com>
edge_sweep_row() computed the clipped endpoint x coordinates with
int32_t subtractions before casting to int64_t. If an edge started at
INT32_MIN and the scanline clipped endpoint was near zero, ey - yL
overflowed before the slope multiply and UBSan flagged the raster
fuzzer path.
Keep the endpoint interpolation and follow-on dx math in 64-bit until
clamping back to int32_t. This preserves the existing rasterizer logic
while avoiding signed overflow for extreme edge coordinates.
Tested:
- meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
The raster paint clip code indexed non-rect clip alpha rows directly,
assuming the clip metadata always matched a full stride*height backing
buffer. Fuzzing showed that reused clip objects can reach those reads
with stale scalar state, which turns the row access in
push_clip_rectangle() into a heap-buffer-overflow.
Reset cached clip geometry on acquire, add a validity check for
non-rect alpha masks, and refuse to build new clip intersections from
an invalid mask. The fallback is an empty clip, which keeps the paint
path safe without affecting well-formed clips.
Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build
Co-authored-by: OpenAI Codex <codex@openai.com>
MemorySanitizer reported use of uninitialized data while building the
SVG document cache used by vector painting. The parser keeps small
aggregate structs on the stack, and their padding could stay poisoned
as they were copied through the open-element stack.
Zero-initialize the parser stack and the temporary span / element
records before filling their fields. That keeps later copies and
container insertions from carrying undefined padding into the MSan
instrumented path.
Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build
Co-authored-by: OpenAI Codex <codex@openai.com>
The GPU fuzzer can build outline data large enough to stress the size
math inside hb_gpu_draw_encode(). Several totals and byte counts were
computed with unchecked unsigned arithmetic before the existing bounds
checks ran.
Use HarfBuzz's overflow helpers for band-index totals, encoded blob
lengths, byte sizes, and recycled-buffer growth. Also rewrite the
uint16-offset limit check so it does not rely on subtracting from an
already-overflowed total.
Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build
Fixes: https://oss-fuzz.com/testcase-detail/6336503637934080
Co-authored-by: OpenAI Codex <codex@openai.com>
Document that raster, vector, and gpu still must not crash,
access out of bounds, or corrupt memory under failing-malloc,
but best-effort early failure is acceptable and complex rollback
logic is not required after OOM.
Co-authored-by: OpenAI Codex <codex@openai.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>
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>
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
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