Commit Graph
15957 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 41de3c3272 [vector] Destruct items in clear() when vector is in error state
The previous fix (d134f888) zeroed `length` but skipped element
destructors. Call shrink_vector(0) instead, which properly destructs
items before clearing length.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 14:19:41 -06:00
Behdad Esfahbod 7433361337 [gpos] Guard cursive attachment reversal
Cursive attachment reversal clears the old child edge before
walking the existing chain and reinstalling reversed links.
If the chain distance does not stay in range for
attach_chain(), reinstalling the reversed edge can truncate
and leave a poisoned chain value.

Pass the buffer length into the reversal helper so it drops
out-of-bounds chains, and use a round-trip fit check before
storing the reversed distance. When the reversed distance does
not fit, leave the old edge detached instead of corrupting
the chain.

Testing: CCACHE_DISABLE=1 meson test -C build --print-errorlogs
Fixes https://issues.chromium.org/issues/496302307
Assisted-by: OpenAI Codex <codex@openai.com>
2026-03-26 14:14:57 -06:00
Behdad Esfahbod cbe62baf81 [raster] Increase max image buffer size
Somebody already hit it it seems.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5874
2026-03-26 13:40:08 -06:00
Behdad Esfahbod 84d821ffac Remove two redundant conditionals
Fixes https://github.com/harfbuzz/harfbuzz/issues/5873
2026-03-25 11:59:58 -06:00
Behdad Esfahbod ef6a54cac3 [glyf] Reject simple glyphs with too few points
Reject simple glyf data that claims fewer points than contours.
Such data cannot describe a valid outline, so fail before
allocating and decoding contour points.

Testing: CCACHE_DISABLE=1 meson test -C b
Assisted-by: OpenAI Codex <codex@openai.com>
2026-03-24 14:26:42 -06:00
Behdad Esfahbod b268ba10ad [font] Fix typo in setting design coords (#5871)
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-8p7p-f952-473p
2026-03-24 11:29:42 -06:00
Behdad Esfahbod e6a9f6e889 [font] Avoid div-by-zero in parent scale
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-fw7p-wr9p-p9ww
2026-03-24 11:29:02 -06:00
Behdad Esfahbod 9b997ccc4e [font] Avoid creating a cycle in set_parent()
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-6f7c-qw56-fvvr
2026-03-24 11:27:51 -06:00
Behdad Esfahbod ebda73ad65 [zlib] Remove unused macro 2026-03-24 11:26:16 -06:00
Behdad Esfahbod 30363077d2 Ignore -Warray-bounds
Fixes https://github.com/harfbuzz/harfbuzz/issues/5738
2026-03-24 11:25:59 -06:00
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 2cde8de822 [raster] Use png_jmpbuf in PNG error callback (#5868)
hb_raster_png_error() switched to png_longjmp() when raster PNG
error handling was hardened. That symbol is only available with
newer libpng headers, but HarfBuzz does not require a minimum
libpng version.

Follow cairo-png.c and jump through png_jmpbuf() instead. This
keeps the error path working with older libpng headers, including
macOS framework builds that pick up pre-1.5 libpng.

Testing:
meson test -C build

Fixes: https://github.com/harfbuzz/harfbuzz/issues/5867
Assisted-by: OpenAI Codex
2026-03-23 12:43:50 -06:00
Behdad Esfahbod c34dd6e24b [buffer] Bounds-check in add_utf() (#5864)
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-q4gc-p4hh-3765
2026-03-22 22:49:14 -06:00
DejanandDK 2763ae13d3 [ot-font] Skip adjusting offsets when all origin values are zero (#5863)
Co-authored-by: DK <dejan@Mac.ht.home>
2026-03-21 21:43:20 -06:00
DejanandDK 5b6645dabb Fix for issue #5847 (#5862)
Co-authored-by: DK <dejan@Mac.ht.home>
2026-03-20 23:33:00 -06:00
Behdad Esfahbod 20fc6583b9 Revert "[rust] Use design coords if available, to set on the Rust side"
This reverts commit cb121fe0368d37ee599c8d4e168a5d139520cbcf.
2026-03-19 12:12:27 -06:00
Behdad Esfahbod 30f8744405 [rust] Use design coords if available, to set on the Rust side
Going to commit since not useful. Just wanted to record the code.
2026-03-19 12:12:27 -06:00
Behdad Esfahbod 488dfcf289 [vector] Reject errored SVG paint bodies
Under failing-malloc, the SVG paint backend could leave the
root body or captured glyph body vector in an error state and
then keep appending to it. Group initialization only checked
group_stack itself, not the nested root body, and glyph
emission reported success even when defs, current body, or
captured scratch had entered vector error state.

Treat an errored root body as init failure, reject cached and
non-cached glyph emission once those vectors enter error, and
stop ignoring push_or_fail() in push_group().

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:56:12 -06:00
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