Commit Graph
15919 Commits
Author SHA1 Message Date
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
Behdad Esfahbod c395ca8a43 [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
2026-03-10 10:30:58 -03:00
Behdad Esfahbod 8339a9b480 [cplusplus] Add raster and vector vtables
Extend hb-cplusplus.hh with shared_ptr/unique_ptr vtables for the
public raster and vector object types when their headers are
included.

Also simplify the local vtable macro so the get_empty/nullptr cases
share one definition instead of duplicating the exact same template
body.

Tested:
- meson compile -C build

Assisted-by: OpenAI Codex
2026-03-10 10:28:56 -03:00
Behdad Esfahbod 77f5a19650 [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
2026-03-10 10:21:28 -03:00
Behdad Esfahbod 3ec2c7c329 [check] Simplify list
https://github.com/harfbuzz/harfbuzz/pull/5812#pullrequestreview-3921617643
2026-03-10 09:56:47 -03:00
Behdad Esfahbod cfd9a52c9d [svg] Gate SVG table processing under HB_NO_SVG (#5814)
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
2026-03-10 00:19:39 -06:00
Behdad Esfahbod 6add360dbf Fix check libraries (#5812)
* Centralize check library lists

* Hide internal raster helper symbols
2026-03-09 22:37:07 -06:00
Behdad Esfahbod 9058176117 Harden raster PNG error handling 2026-03-10 01:20:37 -03:00
Behdad Esfahbod eaf002624d Factor custom object destroy helpers 2026-03-10 01:04:11 -03:00
Behdad Esfahbod 79646aae36 Fix raster and vector destroy ordering 2026-03-10 01:00:31 -03:00
Behdad Esfahbod a940e06ff4 Use push_or_fail in raster SVG paths 2026-03-09 23:09:41 -03:00
Behdad Esfahbod 2329724c1e Fix hb_vector push failure checks 2026-03-09 23:08:02 -03:00
Behdad Esfahbod 9ffd6815b0 Harden raster paint stack allocation failures 2026-03-09 22:46:38 -03:00
Behdad Esfahbod 31b23afc9c Fix raster paint surface cache leak 2026-03-09 22:33:04 -03:00
Behdad Esfahbod dfc64f02c0 raster: add PNG serialization API for images 2026-03-09 23:37:36 +02:00
Quang LuongCodex (AI assistant)Gemini (AI assistant)
7b7d54e33b [arabic] Improve stch measurement pass (#5808)
Use checked arithmetic when calculating the number of extra glyphs
needed during stch processing. Includes a new hb_unsigned_add_overflows
helper in hb-algs.hh.

Co-authored-by: Codex (AI assistant)
Co-authored-by: Gemini (AI assistant)
2026-03-09 15:02:38 -06:00
Behdad Esfahbod fc6eaa5400 [svg] Use std::isfinite
Fixes https://github.com/harfbuzz/harfbuzz/issues/5806
2026-03-09 15:11:23 -03:00
Behdad Esfahbod 6f198a9e39 [raster] Change image reconstruction from box to bilinear
https://github.com/harfbuzz/harfbuzz/pull/5798#issuecomment-4023007382
2026-03-09 18:18:52 +02:00
Behdad Esfahbod 9c6f4c201f raster: add PNG paint_image support via libpng 2026-03-09 18:18:52 +02:00
Khaled Hosny 0e35bd4896 [docs] Improve code blocks
GTK-Doc does not seem to support mark down code blocks markup. Use the
other way, and mark the language as plain text because code coloring
looks a bit ugly.
2026-03-08 00:03:57 +02:00
Khaled Hosny c298b921d6 13.0.1 2026-03-07 20:25:13 +02:00