15939 Commits
Author SHA1 Message Date
Khaled Hosny 6f4c5cec30 13.2.1 2026-03-19 16:09:56 +02:00
Khaled Hosny 09b79d14a0 [message] Fix start/end table GPOS message
Fix broken format from the previous change.
2026-03-19 16:07:30 +02:00
Khaled Hosny 5ad3909af4 13.2.0 2026-03-19 00:45:24 +02:00
Khaled Hosny 0ccf380469 [message] Improve start/end table GSUB/GPOS with HB_TAG_NONE
Use hb_tag_to_string() so we would get an empty string in this case
instead of calling HB_UNTAG() directly which would give us nul bytes
that would truncate the string.

Instead of:
trace: start table GSUB script tag '	buffer: [a=0]

We now get:
trace: start table GSUB script tag ''	buffer: [a=0]
2026-03-19 00:43:07 +02: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
Khaled Hosny 7191f88e56 Add start/end compose/decompose messages
Similar to start/end reorder messages. It does not give details on what
have been composed or decomposed as this seems to be tricky and one can
always deduce that from the changes to buffer contents.
2026-03-18 23:36:54 +02:00
Khaled Hosny 257769a9d2 [ot-shape] Add hb_ot_shape_get_buffer_format_serial() (#5857) 2026-03-18 10:24:52 -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 b4115f23ee [subset] Harden renormalizeValue for malformed avar triples
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
2026-03-17 09:12:35 -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 2b93ac44e1 [raster] Fast-path axis-aligned clip rectangles on masks
hb_raster_paint_push_clip_rectangle() already has an O(1) fast path for
axis-aligned rectangle clips when the existing clip is also a rectangle.
If the existing clip is an alpha mask, the code fell back to the generic
quad rasterization loop even though the new clip was still axis-aligned.

That makes malformed COLR inputs spend large amounts of time in the per-
pixel inside-quad test. Intersect axis-aligned rectangle clips with an
existing alpha mask by copying only the intersecting row spans.

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

Assisted-by: OpenAI Codex
2026-03-14 13:25:34 -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
Khaled Hosny 70b812d8d2 13.1.1 2026-03-13 03:08:03 +02:00
Behdad Esfahbod 70de901d39 [cmake] Add raster and vector libraries
Wire harfbuzz-raster and harfbuzz-vector into the
community-maintained CMake build so they are built,
installed, and exported like the existing optional
libraries.

Also install their public headers, generate pkg-config
files for them, and expose HB_HAS_SUBSET/HB_HAS_RASTER/
HB_HAS_VECTOR in hb-features.h.

Testing:
meson test -C build

Assisted-by: OpenAI Codex
2026-03-13 01:21:13 +02:00
Behdad Esfahbod 01f1125c8c [varStore] Handle >65535 items per encoding (#5840)
Split optimized encodings into multiple VarData subtables before
rebuilding VariationIndex mappings. This keeps itemCount within the
16-bit limit when the optimizer produces more than 65535 rows for a
single encoding.

Add a regression test that mirrors the FontTools overflow case and
checks the split boundaries in the remapped VarIdx output.

Testing: meson compile -C build test-item-varstore
Testing: ./build/src/test-item-varstore
Fixes: #5839
Assisted-by: OpenAI Codex
2026-03-12 10:29:21 -06:00
Behdad Esfahbod 6ad6a2fe82 [COLR] Propagate clip extents failures
ClipList::get_extents() returned true for any matching clip record,
even when the underlying ClipBox rejected the request.

That left the output extents uninitialized and the paint path could
pass them to scale_glyph_extents(), which shows up under
MemorySanitizer in clipped COLRv1 raster painting.

Return the ClipRecord result directly so invalid clip boxes fail
cleanly instead of exposing uninitialized extents.

Fixes: https://oss-fuzz.com/testcase-detail/4659742604853248
Assisted-by: OpenAI Codex
2026-03-12 17:19:14 +02:00
Behdad EsfahbodandQuang Luong 91085cd990 Guard VarData itemCount overflow (#5836)
Reject oversized merged VarData row sets before assigning them to the
16-bit itemCount field. This avoids truncating the serialized allocation
size and prevents the subsequent row write loop from running out of
bounds.

 src/hb-ot-layout-common.hh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Co-authored-by: Quang Luong <oss@engineer.ink>
2026-03-12 08:57:35 -06:00
Behdad Esfahbod 3786b83fa6 [amalgamation] Add HB_HAS_SUBSET and share SVG helpers (#5835)
Add HB_HAS_SUBSET to hb-features.h and wire it through the same
HAVE_* feature plumbing used by the other HB_HAS_* macros.

Refactor the raster/vector SVG helper code so the duplicated
private helpers live in shared internal headers, avoiding
duplicate definitions when sources are combined in a single
translation unit.

Testing: meson compile -C build

Assisted-by: OpenAI Codex
2026-03-12 08:32:37 -06:00
Behdad Esfahbod a7a077d95c Merge branch 'main' into svgz 2026-03-11 23:55:41 -06:00
Behdad Esfahbod 4da15dadff [meson] Add raster/vector feature macros
Raster and vector libraries were configurable, but hb-features.h.in
did not expose matching HB_HAS_* macros.

Set HAVE_RASTER and HAVE_VECTOR during configuration, include both
features in the generated hb-features.h list, and add them to the
gtk-doc section index.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-03-12 02:53:11 -03:00
Behdad Esfahbod 1607db6970 [svg] Keep zlib private to raster and vector SVG decoding
The core libharfbuzz SVG table code should not include zlib headers or
link against zlib. Only the raster and vector libraries need to
normalize svgz documents before parsing them.

Move the gzip decoder into a private hb-zlib translation unit that is
built only by harfbuzz-raster and harfbuzz-vector, and move SVG blob
normalization into a private helper header used only there. Keep the
shared SVG table and cache logic in libharfbuzz free of zlib includes.

Assisted-by: OpenAI Codex
2026-03-12 02:41:44 -03:00
Behdad Esfahbod 8fc1d1bfd1 [vector] Allow duplicate SVG refs during subsetting
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
2026-03-12 01:46:46 -03:00
Garret Rieger 07a9ad2ed1 For the CFF overflow fix use remaining instead of total bytes to avoid any possible overflow in the total bytes count. (#5826) 2026-03-11 19:15:21 -06:00
Behdad Esfahbod fd8535af45 [vector] Keep extracted root SVG overflow visible
When hb-vector emits a root SVG glyph document as a nested <svg>, browser
SVG renderers clip it to that nested viewport. OpenType SVG root documents
are not meant to be clipped that way.

Set overflow="visible" on extracted root SVG glyphs so browser rendering
matches the intended OpenType SVG behavior.

Tested:
- meson test -C build

Assisted-by: OpenAI Codex
2026-03-11 21:03:31 -03:00
Behdad Esfahbod d9116dda9c [svg] Use em-square root viewport fallback
Root SVG documents in OpenType SVG glyph data can omit width and height
while still defining a viewBox. HarfBuzz was falling back to the viewBox
size in that case, which made fonts like emojione-svg.otf render with the
wrong placement and scale.

Use the font upem as the fallback viewport size for the root SVG document.
Raster now applies that when mapping the root viewBox, and vector injects
matching width/height on extracted root SVG glyph documents.

Tested:
- meson test -C build

Assisted-by: OpenAI Codex
2026-03-11 20:51:41 -03:00
Behdad Esfahbod 00da68ef5c [svg] Share svgz normalization across raster and vector
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
2026-03-11 20:23:51 -03:00
Garret Rieger 2c99665d85 Fix potential buffer overwrite in CFF/CFF2. (#5825)
Caused by integer overflow in the total_size() calculation.

Based on fix provided by Quang Luong <oss@engineer.ink>
2026-03-11 16:49:33 -06:00
Behdad Esfahbod fc5bc355d3 [raster] Simplify SVG render cleanup
Simplify hb_raster_svg_render() to use one cleanup path
and keep the blob lifetime handling in one place. While
doing that, drop dead checks that only depended on
hb_blob_reference() returning nullptr or hb_blob_get_data()
returning nullptr for non-empty blobs.

Testing:
- meson test -C build

Assisted-by: OpenAI Codex
2026-03-11 15:57:43 -03:00
Behdad Esfahbod b7e4f5fd62 [raster] Support gzip-compressed SVG documents
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
2026-03-11 14:18:31 -03:00
Behdad Esfahbod 708bf4a0c8 [arabic] Cap stch expansion per run (#5823)
Cap each stch run to at most 256 output glyphs.

This keeps pathological stretch runs from expanding to unbounded
sizes, and switches the repeat-count math to 64-bit intermediates so
the cap is applied before 32-bit arithmetic can wrap.

The existing checked accumulation and buffer growth logic stays in
place, covering both the per-run overflow and multi-run accumulation
cases reported in the recent stch advisories.

Tested: meson test -C build --suite shape
Assisted-by: OpenAI Codex
2026-03-11 10:53:09 -06:00
Khaled Hosny 68d19d6964 13.1.0 2026-03-11 04:01:41 +02:00
Behdad Esfahbod 21f9461bd0 [subset] Validate rebasing axis limits locally
Drop malformed normalized axis ranges only at the tuple
rebasing boundary, where that invariant is actually required,
instead of rejecting them during subset plan construction.

This keeps avar2 full-instance behavior intact while preventing
invalid axis limits from reaching rebase_tent().

Tested:
- ./build/src/test-instancer-solver
- ./build/src/test-item-varstore
- meson test -C build --suite subset --print-errorlogs --no-rebuild

Assisted-by: OpenAI Codex
2026-03-10 11:58:52 -06:00
Behdad Esfahbod cc44a3a072 [subset] Allow avar2 pinned normalized points
Keep rejecting malformed normalized axis ranges for partial
instancing, but allow pinned points. avar2 full instances can
legitimately normalize outside [-1, 1], and those coordinates do
not flow into tent rebasing.

Tested:
- ./build/src/test-instancer-solver
- ./build/src/test-item-varstore
- meson test -C build --suite subset --print-errorlogs --no-rebuild

Assisted-by: OpenAI Codex
2026-03-10 11:58:52 -06:00
Behdad Esfahbod bc4bbced05 [subset] Reject malformed normalized axis ranges
Reject invalid normalized axis triples during subset plan
construction so malformed avar remapping does not reach tuple
instancing.

Keep a defensive guard in the instancer solver as a backstop
against future bad callers.

Tested:
- ./build/src/test-instancer-solver
- ./build/src/test-item-varstore
- ./build/src/test-tuple-varstore

Fixes: https://oss-fuzz.com/testcase-detail/6119821501857792
Assisted-by: OpenAI Codex
2026-03-10 11:58:52 -06:00
Khaled Hosny 3d369f5144 [subset/cff1] Fix subsetting font dicts with old_to_new_glyph_mapping
The code was assuming old_glyph to be monotonically increasing and
cashed the font dict accordingly, but that is not the case with the test
font and code.

I’m not entirely sure about this fix, but not caching the font dict
seems to fix the issue for me.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5799
2026-03-10 19:47:03 +02:00
Behdad Esfahbod d2ecd9b370 [fuzzing] Fix hb-raster/vector fuzzer issues (#5816)
* [fuzzing] Guard raster/vector create_or_fail results

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

* [vector] Avoid OOM leak in paint initialization

hb_vector_paint_ensure_initialized() used group_stack.push() and
then treated the returned pointer as a normal success indicator.
On allocation failure push() returns the Crap() sentinel, so the
subsequent root->alloc(4096) allocated backing storage into the
failure sink and leaked under malloc-failure fuzzing.

Use push_or_fail() instead and only allocate the root body after a
real push succeeds.

Tested:
- build/test/fuzzing/hb-vector-fuzzer test/fuzzing/fonts/TwemojiMozilla.subset.ttf

Assisted-by: OpenAI Codex

* [vector] Avoid double-free on blob creation failure

hb_svg_blob_from_buffer() handed buffer ownership to hb_blob_create()
in the non-recycled path and then ran its own failure cleanup. When
hb_blob_create() failed, it had already invoked the destroy callback,
so the local cleanup freed the same buffer again.

Use hb_blob_create_or_fail() there instead so allocation failure
returns nullptr without triggering the empty-blob fallback and its
conflicting cleanup semantics.

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

Assisted-by: OpenAI Codex

* [vector] Avoid double-free in draw blob creation

Mirror the blob-creation failure fix from vector paint in the SVG
draw path. The non-recycled branch handed ownership to
hb_blob_create(), which may already run the destroy callback on
failure, and then fell into local cleanup that freed the same buffer
again.

Switch that branch to hb_blob_create_or_fail() so failure reports
nullptr without conflicting cleanup.

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

Assisted-by: OpenAI Codex

* [vector] Fix OOM handling in SVG subset id collection

hb_svg_add_unique_id() used v->push() and tested the returned
pointer for null. hb_vector_t::push() reports allocation failure via
the vector error state and returns the Crap() sentinel, so the old
check did not reliably stop on OOM.

Check v->in_error() after push() before writing into the new slot.

Assisted-by: OpenAI Codex

* [vector] Guard paint render after init failure

hb_vector_paint_render() assumed ensure_initialized() had created
the root group body and indexed group_stack[0] unconditionally.
Under malloc-failure fuzzing, initialization can fail while extents
are already set, leaving group_stack empty and causing a null-deref.

Return nullptr if initialization did not produce the root group.

Assisted-by: OpenAI Codex

* [vector] Propagate paint init failures

hb_vector_paint_ensure_initialized() can fail under malloc-failure
fuzzing, but several paint callbacks assumed the root group existed
immediately afterward and accessed current_body() or group_stack[0].

Make initialization report success and bail out at the callers that
require the root group. Also use push_or_fail() for the extra group
stack entries created by grouping and glyph caching.

Assisted-by: OpenAI Codex

* [raster] Bound SVG path parsing work

hb_raster_svg_parse_path_data() had no complexity cap, unlike the
other new raster SVG subsystems that already bound recursion depth,
attribute count, and gradient stops. Malformed path data could
therefore spend excessive time in parsing and bbox/render work under
fuzzing.

Add a hard limit on parsed path segments and expose it through
hb-limits.hh so the budget is defined alongside the other shared
parser/work limits.

Assisted-by: OpenAI Codex

* [raster] Bound temporary clip mask buffers

hb_raster_paint_push_clip_from_emitter() and the general clip
rectangle path could allocate and clear full-surface temporary A8 clip
masks with no explicit size cap, leading to timeout-scale work on
malformed inputs.

Reuse the raster buffer size policy for these temporary masks as well,
and move that limit into hb-limits.hh so raster images and clip masks
share the same bound.

Assisted-by: OpenAI Codex

* [raster] Reduce buffer size cap

Lower HB_RASTER_MAX_BUFFER_SIZE from 1<<30 to 1<<24 so the shared
raster image / clip-mask limit meaningfully constrains pathological
fuzzer inputs instead of allowing timeout-scale temporary buffers.

Assisted-by: OpenAI Codex
2026-03-10 08:55:44 -06:00
Behdad Esfahbod 331ef99cd8 [raster] Reduce buffer size cap
Lower HB_RASTER_MAX_BUFFER_SIZE from 1<<30 to 1<<24 so the shared
raster image / clip-mask limit meaningfully constrains pathological
fuzzer inputs instead of allowing timeout-scale temporary buffers.

Assisted-by: OpenAI Codex
2026-03-10 11:40:02 -03:00
Behdad Esfahbod a0714506d6 [raster] Bound temporary clip mask buffers
hb_raster_paint_push_clip_from_emitter() and the general clip
rectangle path could allocate and clear full-surface temporary A8 clip
masks with no explicit size cap, leading to timeout-scale work on
malformed inputs.

Reuse the raster buffer size policy for these temporary masks as well,
and move that limit into hb-limits.hh so raster images and clip masks
share the same bound.

Assisted-by: OpenAI Codex
2026-03-10 11:39:03 -03:00
Behdad Esfahbod 95462193eb [raster] Bound SVG path parsing work
hb_raster_svg_parse_path_data() had no complexity cap, unlike the
other new raster SVG subsystems that already bound recursion depth,
attribute count, and gradient stops. Malformed path data could
therefore spend excessive time in parsing and bbox/render work under
fuzzing.

Add a hard limit on parsed path segments and expose it through
hb-limits.hh so the budget is defined alongside the other shared
parser/work limits.

Assisted-by: OpenAI Codex
2026-03-10 11:14:54 -03:00
Behdad Esfahbod 4ec5290084 [vector] Propagate paint init failures
hb_vector_paint_ensure_initialized() can fail under malloc-failure
fuzzing, but several paint callbacks assumed the root group existed
immediately afterward and accessed current_body() or group_stack[0].

Make initialization report success and bail out at the callers that
require the root group. Also use push_or_fail() for the extra group
stack entries created by grouping and glyph caching.

Assisted-by: OpenAI Codex
2026-03-10 10:52:40 -03:00
Behdad Esfahbod adf7e9dcb2 [vector] Guard paint render after init failure
hb_vector_paint_render() assumed ensure_initialized() had created
the root group body and indexed group_stack[0] unconditionally.
Under malloc-failure fuzzing, initialization can fail while extents
are already set, leaving group_stack empty and causing a null-deref.

Return nullptr if initialization did not produce the root group.

Assisted-by: OpenAI Codex
2026-03-10 10:50:02 -03:00
Behdad Esfahbod 4fd90c836a [vector] Fix OOM handling in SVG subset id collection
hb_svg_add_unique_id() used v->push() and tested the returned
pointer for null. hb_vector_t::push() reports allocation failure via
the vector error state and returns the Crap() sentinel, so the old
check did not reliably stop on OOM.

Check v->in_error() after push() before writing into the new slot.

Assisted-by: OpenAI Codex
2026-03-10 10:42:29 -03:00
Behdad Esfahbod b6b8f8dcca [vector] Avoid double-free in draw blob creation
Mirror the blob-creation failure fix from vector paint in the SVG
draw path. The non-recycled branch handed ownership to
hb_blob_create(), which may already run the destroy callback on
failure, and then fell into local cleanup that freed the same buffer
again.

Switch that branch to hb_blob_create_or_fail() so failure reports
nullptr without conflicting cleanup.

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

Assisted-by: OpenAI Codex
2026-03-10 10:41:10 -03:00