Commit Graph
15901 Commits
Author SHA1 Message Date
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
Behdad Esfahbod 176d374b47 Raster packed (#5795)
* raster: use hb_packed_t for unaligned BGRA32 access

* algs: support encapsulated hb_packed_t and fix raster callsites
2026-03-07 09:59:47 -07:00
Behdad Esfahbod f1098701e1 raster-paint: clear stale surfaces on render failure 2026-03-06 23:05:31 -03:00
Behdad Esfahbod c6108e9633 raster-paint: handle reflected transforms in rectangle clip test 2026-03-06 23:05:16 -03:00
Behdad Esfahbod 1b744652fe raster-paint: guard BGRA image dimensions and blob size math 2026-03-06 23:04:58 -03:00
Behdad Esfahbod 0109116383 vector: gate localeconv_l and fall back to localeconv
Fixes https://github.com/harfbuzz/harfbuzz/issues/5791
2026-03-06 22:47:52 -03:00
Behdad Esfahbod 31af2b94a0 raster: avoid unsigned wrap in clip-space sampling coords 2026-03-06 22:42:18 -03:00
Behdad Esfahbod 8db165abf6 raster: advance radial sample coords on skipped pixels 2026-03-06 22:39:04 -03:00
Khaled Hosny a0fc099681 13.0.0 2026-03-04 22:28:50 +02:00
Behdad Esfahbod 19f54f2cfd Merge pull request #5784 from harfbuzz/downgrade-cff-hintmask
[subset] Fix CFF2->CFF1 specializer hintmask encoding
2026-03-04 12:55:54 -07:00
Khaled Hosny 1cd38d1c56 [meson] Add thread_dep to harfbuzz-subset as well
Adapted patch from:
https://git.libreoffice.org/core/+/8f6d4fb1a4bbb689ca748dd033ceaa87d94a1a3d%5E%21
2026-03-04 19:58:32 +02:00
Khaled Hosny 64ad598432 [vector] Move documentation to .cc when applicable 2026-03-04 19:04:12 +02:00
Behdad EsfahbodandClaude Opus 4.6 6a1c028a61 [buffer] Add hb_buffer_changed() (#5755)
* [buffer] Add hb_buffer_changed()

To be called by message callbacks if they modify buffer glyph indices,
to update internal caches (currently the buffer digest).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* [buffer] Implement changed() callback and hook up to OT shaper.

* Only install buffer changed() callback if messaging enabled

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 09:16:54 -07:00
Khaled Hosny b91d4b8d75 Add meson options to disable building harfbuzz-subset 2026-03-04 18:12:45 +02:00
Khaled Hosny 72ee0c2dfd Add meson options to disable building harfbuzz-vector 2026-03-04 18:12:45 +02:00
Khaled Hosny 9520926168 Add meson options to disable building harfbuzz-raster 2026-03-04 18:12:45 +02:00
Behdad Esfahbod 2c3a86ac06 [vector] Fix SVG Y translation sign 2026-03-03 15:45:25 -03:00
Behdad Esfahbod c8b6b6895c Minor generator provenance change 2026-03-03 06:27:43 -03:00
Behdad Esfahbod 47097cf697 Add Rust output to vowel constraints generator 2026-03-03 06:18:08 -03:00