Commit Graph
17140 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 2f8fb68973 [map] Fix use-after-free when updating a map from itself
hb_hashmap_t::update() iterates other's items array while inserting
each pair into *this with set().  When other is *this and occupancy
sits on a growth threshold (5 of 8, 10 of 16, ...), the first set()
calls alloc(), which frees the items array the iterator is still
walking, so the rest of the loop reads freed memory.  The existing
in_storage() guard only protects set()'s own key/value references,
not this iterator.

Merging a map into itself cannot change it, so make update() a no-op
in that case with an early &other == this return, mirroring the
self-check in hb_vector_t.  hb_map_update() is the only caller.

Regression tests are added in src/test-map.cc (including the tombstone
case at 42 used / 10 live slots) and test/api/test-map.c; both fail
under ASan without the fix.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-7TMM2Z2T.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 16:35:27 -06:00
Behdad Esfahbod e8f8ee612f [subset] Ignore seac component lookups in CID-keyed CFF fonts (#6506)
CID-keyed CFF charsets contain CIDs, not the standard SIDs needed by seac.
Interpreting the invalid operator can therefore retain unrelated glyphs
when their CIDs collide with the component SIDs from StandardEncoding.

Reject CID-keyed fonts in get_seac_components so both subset closure and
dependency collection skip these invalid lookups. Add a synthetic CID
font with colliding CIDs and check that only .notdef and the requested
glyph enter the subset plan.

The regression fails before the fix with four retained glyphs instead of
two. All 294 Meson tests pass, including the subset and API suites.

Assisted-by: OpenAI Codex
2026-10-30 16:10:52 -06:00
Behdad EsfahbodandClaude Opus 4.8 969dbf7931 [cairo] Fix recursion, leak, cluster abort and COLR paint DoS in hb-cairo (#6497)
* [cairo] Paint nested color glyphs inline to bound recursion

hb_cairo_paint_color_glyph() accepted the color_glyph paint callback
and drew the nested glyph with cairo_show_glyphs(), which re-enters
hb_font_paint_glyph() through a new cairo scaled font with a fresh
hb_paint_context_t.  The glyph decycler, HB_MAX_NESTING_LEVEL and the
edge budget therefore start over at every level, so two glyphs that
paint each other with PaintColrGlyph recurse until the stack is
exhausted.  The per-scaled-font hb_cairo_budget_t cannot bound this
either: the nested glyph is shown through a different scaled font, so
each level gets its own budget.

Decline the callback, returning false exactly as hb-raster's does, so
the COLR (and hb-ft-colr) walk paints the nested glyph inline under the
decycler and depth limits of the walk already in progress.

A regression test with two PaintColrGlyph glyphs that paint each other
is added to test/api/test-cairo.c; it aborts on the unpatched library
and passes with the fix.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-VPKA505E.

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

* [cairo] Don't leak the hb_font_t created per scaled font

hb_cairo_init_scaled_font() must hand exactly one reference of the
hb_font_t to the cairo_scaled_font_t.  For a face-based font face
(hb_cairo_font_face_create_for_face()) it creates the font with a
reference count of 1, but then still called hb_font_reference() before
attaching it, so the creating reference was never released.  Every
finalized scaled font therefore leaked an hb_font_t, pinning its
hb_face_t, the font blob and the accelerators until the process exits.
Cairo finalizes scaled fonts during normal operation once its cache
fills, so the leak accumulates as content selects distinct sizes,
transforms or font options.

Take the extra reference only in the branch where the font is the
shared one owned by the cairo font face (the font-based constructor),
and transfer the freshly created font as-is.  The set_user_data result
is now checked and the font released on failure, matching the
budget/color-cache idiom a few lines below and the font-face
constructors in the same file.

A callback installed with hb_cairo_font_face_set_font_init_func() that
returns a different font keeps its historical behavior: the returned
font is referenced rather than assumed to transfer ownership, so no
in-tree contract changes and no caller can turn into a use-after-free.
hb-view uses the font-based constructor and was unaffected.

A regression test in test/api/test-cairo.c registers a face destroy
notifier, draws through a face-based font face, flushes cairo's
scaled-font cache and asserts the face was destroyed; it fails on the
unpatched library and passes with the fix.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-BAUN9JN4.

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

* [cairo] Map non-monotone buffer clusters to one cairo cluster

hb_cairo_glyphs_from_buffer() asserted that buffer clusters are monotone
in the buffer direction, but hb_shape() does not guarantee that:
HB_BUFFER_CLUSTER_LEVEL_CHARACTERS, shaping that hits the ops limit
mid-lookup, and Indic reordering corner cases can all produce
non-monotone clusters.  The function runs from HarfBuzz's own cairo
text_to_glyphs callback on attacker-controlled text and fonts, so the
assertion was an input-dependent abort (and, with NDEBUG, an unchecked
backward walk off the ends of the utf8 buffer).

The cluster-counting loop that already walks the buffer now detects a
step against the buffer's direction and falls back to a single cairo
cluster mapping all of the utf8 to all of the glyphs, which cairo
accepts.  The monotonicity assertions in the fill step then hold by
construction and glyph output is unchanged for monotone buffers.

A regression test in test/api/test-cairo.c feeds monotone and
non-monotone LTR/RTL buffers through both cluster modes and checks the
cluster counts and byte/glyph totals; it aborts on the pristine tree.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-T4PZ1H72.

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

* [cairo] Charge compositing operations to the glyph budget

hb-cairo's per-glyph work budget was spent only on emitted path segments,
so a COLRv1 font could pay once for a clip outline (push_clip_glyph) and
then have cairo re-rasterize it for every PaintSolid/gradient/group
composite under it, up to the COLR edge limit.  That is the
multiplication of limits the shared budget in hb-limits.hh exists to
prevent: a 2 KB font kept hb-view busy for over a minute on one glyph.

Charge every composite in the cairo backend, where the cost is incurred
and where the sibling backends already charge per operation (hb-raster
charges pixel area per paint).  hb_cairo_context_t now counts the
segments of the current path and keeps a stack of the clip paths in
force, maintained by the push_clip_* callbacks and pop_clip; spend_paint()
charges every fill, paint, group and gradient with (1 + segments) times a
per-source weight, squared when more than one path is in force since
cairo then intersects the paths per operation.  These segment and clip
counts are inputs to the existing budget_remaining counter; they are not
a separate per-callback limit.  The weights (HB_BUDGET_512 for
solid/group, 1024 for linear/radial gradients, a new HB_BUDGET_8192 for
the sweep mesh pattern) follow per-composite timings measured on
cairo 1.18.

Nested color glyphs are already painted inline by the color_glyph
callback, so their composites are charged against the clips in force at
that point; no change is needed there.

Behaviour change: a glyph whose composites exceed the budget (about 32k
segment-composites, roughly a second of cairo time at hb-view's default
size) is truncated best-effort, as outline work already is.  All glyphs
of the COLRv1 glyf (static and variable) and CFF2 test fonts render
byte-identically through hb-view with and without this change.

A regression test with a generated 3 KB font is added to
test/api/test-cairo.c alongside its fontTools generator; it finishes in
about a second once the paints are charged and guards against
reintroduction through the meson test timeout rather than a
discriminating assertion.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-38OVH0N4.

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

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:26:28 -06:00
Behdad Esfahbod 7768296945 [gpu] Skip paint layers with empty clip outlines (#6483)
The draw encoder returns the empty blob for outlines without curves.
Treating it as a clip sub-blob leaves a layer referring to the next
payload or the end of the encoded data. Cache empty glyph and path
clips separately and skip their consuming layers. Preserve the
paint encoder's no-ink contract when only group operations remain,
returning an empty blob with zero extents.

Use fallible blob creation for gradient payloads so allocation failure
cannot produce the same zero-length sub-blob references.

Add an API regression using an ordinary font and paint callbacks,
covering solid and gradient layers, empty paths, groups, and clip slot
reuse. Validate the surviving layer's outline and band references.
The regression fails on the original encoder; the full Meson suite
passes (274 tests).

Reported by Anthropic's OSS Scanner as ANT-2026-5Z1FLVCW.

Assisted-by: OpenAI Codex
2026-10-30 15:07:23 -06:00
Behdad Esfahbod 041e5a311b [ot-layout] Collect glyph alternates without dangling references (#6482)
hb_pair() preserves references to lvalue arguments. The alternate
collection callbacks returned pairs referencing their own by-value
parameters, so the next iterator stage read them after the call ended.

Pass each AlternateSubst glyph directly to the collector helper, which
already encodes its alternate index. This also keeps alternate_count
keyed by the original glyph. Return a value pair for SingleSubst format
1, as the subsetting path already does.

Cross-check collected maps against the per-glyph getter for four
SourceSansPro lookups. The alternate and both SingleSubst format 1
cases fail on the previous code; the format 2 control passes.

Testing: meson test -C build (292 passed; check-symbols skipped on
macOS). All five alternate API tests also pass under ASan and UBSan,
with stack-use-after-return detection enabled.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-N7S3EYU4.

Assisted-by: OpenAI Codex
2026-10-30 15:04:54 -06:00
Behdad Esfahbod 6f6ed4cd5c [vector] Share recycling metadata across renderers (#6480)
Use one hidden user-data key for vector blob metadata. A static key in
its header gives each renderer a different address, so a blob recycled
between renderers can retain a user-data entry for released metadata.

Clear in_replace after replace_buffer() returns, including when the
buffer stays at the same address and its destroy callback is skipped.
Otherwise the final destruction keeps the metadata allocation alive.

Exercise cross-renderer and in-place recycling in all four SVG/PDF draw
and paint paths. The cross-renderer case fails under ASan before the
fix. With the fix the sanitizer check and all 293 Meson tests pass, and
macOS leaks reports no leaks (five metadata allocations before clearing
the in_replace flag).

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-HAG1BPA1
and ordinary bug ANT-2026-YE77VHKY.

Assisted-by: OpenAI Codex
2026-10-30 15:03:23 -06:00
Behdad Esfahbod 4971496028 [subset/CBDT] Check append lengths before reserving and copying data (#6485)
Check the combined image-data length for unsigned overflow and ensure
it fits the vector's signed length argument. Resize the output only
after those checks, then copy at the saved old length. Both callers
already propagate failure to the serializer.

Extend the allocation-failure test with small simulated boundary cases
for an unrepresentable total and a wrapping sum. Each starts with a
fresh vector, and the allocator refuses large requests as a backstop.
The new regression fails before the fix without allocating large
buffers. All 293 tests pass, and test-cbdt-cache passes under ASan and
UBSan, including the existing required-allocation failure checks.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-N6HMDRS8.

Assisted-by: OpenAI Codex
2026-10-30 15:01:41 -06:00
Behdad Esfahbod 2134638033 [ft] Copy color bitmaps while the face is locked (#6486)
The glyph slot belongs to the shared FreeType face. Copy its bitmap
and dimensions before releasing the face lock, then query extents
and invoke the image callback without the lock. Fail if the bitmap
copy cannot be allocated.

Add a bounded shared-font paint regression using the existing emoji
fixture. Check BGRA blob dimensions and reenter the font from the
image callback. The test crashes before the fix and passes after it.
The full Meson suite passes (274 tests).

Reported by Anthropic's OSS Scanner as ANT-2026-ANVKHBVD.

Assisted-by: OpenAI Codex
2026-10-30 15:01:04 -06:00
Behdad Esfahbod 02b4af88a6 [sanitize] Drop unused writable flag from the context (#6496)
hb_sanitize_context_t::writable is only ever written (in the
constructor and init()) and never read.  The edit/neuter code that
consulted it was removed in 665afc08f6 ("[sanitize] Remove
table-altering code parts") and 83dc4d1d35 ("[sanitize] Don't do
edit-sanitize cycle"); the flag was left behind as dead state.

Remove it.  No functional change; the full Meson suite passes
(274 tests).

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:55:14 -06:00
Behdad Esfahbod a763a612d1 [aat] Reject zero-sized lookup format 10 values (#6487)
Require each format 10 value to occupy at least one byte. Otherwise a
lookup can declare covered glyphs without backing data for those values,
bypassing the sanitizer work charged for checking the array.

Add a compact lookup sanitizer regression covering sizes zero through
five, existing supported sizes, and truncated payloads. The regression
rejects the original zero-sized case and accepts the supported controls.
All 294 Meson tests pass, including the shape suite, and the new test
passes under ASan and UBSan.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-F9Y85YHV.

Assisted-by: OpenAI Codex
2026-10-30 14:54:49 -06:00
Behdad Esfahbod 68ee3a923e [graphite2] Stop shaping when output buffer growth fails (#6489)
Check ensure(glyph_count) before writing Graphite output. Release the
feature values and segment and return failure when buffer growth fails.

Add a small synthetic font and a bounded regression that refuses buffer
growth via max_len. The normal path produces 164 glyphs; the failure path
retains the original input length and reports allocation failure. Include
the font generator, whose output matches the checked-in fixture.

The new regression fails before the fix under ASan and passes afterward.
All 276 tests pass with Graphite2 enabled; the regression also passes under
ASan and UBSan.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-HEQW39B7.

Assisted-by: OpenAI Codex
2026-10-30 14:53:51 -06:00
Behdad EsfahbodandClaude Opus 4.8 022a9e475a [cairo] Charge compositing operations to the glyph budget
hb-cairo's per-glyph work budget was spent only on emitted path segments,
so a COLRv1 font could pay once for a clip outline (push_clip_glyph) and
then have cairo re-rasterize it for every PaintSolid/gradient/group
composite under it, up to the COLR edge limit.  That is the
multiplication of limits the shared budget in hb-limits.hh exists to
prevent: a 2 KB font kept hb-view busy for over a minute on one glyph.

Charge every composite in the cairo backend, where the cost is incurred
and where the sibling backends already charge per operation (hb-raster
charges pixel area per paint).  hb_cairo_context_t now counts the
segments of the current path and keeps a stack of the clip paths in
force, maintained by the push_clip_* callbacks and pop_clip; spend_paint()
charges every fill, paint, group and gradient with (1 + segments) times a
per-source weight, squared when more than one path is in force since
cairo then intersects the paths per operation.  These segment and clip
counts are inputs to the existing budget_remaining counter; they are not
a separate per-callback limit.  The weights (HB_BUDGET_512 for
solid/group, 1024 for linear/radial gradients, a new HB_BUDGET_8192 for
the sweep mesh pattern) follow per-composite timings measured on
cairo 1.18.

Nested color glyphs are already painted inline by the color_glyph
callback, so their composites are charged against the clips in force at
that point; no change is needed there.

Behaviour change: a glyph whose composites exceed the budget (about 32k
segment-composites, roughly a second of cairo time at hb-view's default
size) is truncated best-effort, as outline work already is.  All glyphs
of the COLRv1 glyf (static and variable) and CFF2 test fonts render
byte-identically through hb-view with and without this change.

A regression test with a generated 3 KB font is added to
test/api/test-cairo.c alongside its fontTools generator; it finishes in
about a second once the paints are charged and guards against
reintroduction through the meson test timeout rather than a
discriminating assertion.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-38OVH0N4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:53:31 -06:00
Behdad Esfahbod c34cf564b1 [ft] Allow font queries from color paint callbacks (#6490)
Release the face lock around solid, gradient, and custom palette
callbacks. Keep lazy FreeType color-stop reads locked and give each
getter call its own iterator, so callbacks can query the same font
without deadlocking or disturbing another stop query.

Snapshot the selected palette once per COLRv1 traversal, shared by
the bounds and paint passes. Nested paints can select a different
palette on the face; they must not change the outer paint's colors.
Return failure if the palette copy cannot be allocated. Stops remain
lazy and no cache policy or limits change.

Add a bounded callback regression with the existing COLRv1 fixture.
It queries font extents, performs nested paints with another palette,
and checks repeated and paged stop reads against the OT backend.
The original code times out; unlocking without copying the palette
fails the color comparison. The full Meson suite passes: 274 tests, no failures.

Reported by Anthropic's OSS Scanner as ANT-2026-YPLDSFHA.

Assisted-by: OpenAI Codex
2026-10-30 14:52:35 -06:00
Behdad Esfahbod f9fcba7272 [repacker] Prevent matrix vertex size checks from wrapping (#6491)
AnchorMatrix's offset array size was multiplied in unsigned arithmetic.
A small vertex with 46341 rows could therefore be accepted as a
46341-column matrix, leading to excessive work and allocation during
subtable splitting. PairPosFormat2 had the same problem on 32-bit
platforms.

Use the existing size_t saturating multiply helper and compare against
the payload length after checking the header. This preserves the width
of PairPosFormat2's size computation and avoids overflow in the header
addition as well.

Add bounded internal vertex tests for wrapping dimensions, exact valid
sizes, truncated payloads and headers, and empty matrices. The anchor
regression fails against the unchanged code without large allocations.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-7E6A2QQS.

Testing: meson compile -C build -j4; meson test -C build
(all 274 tests passed).

Assisted-by: OpenAI Codex
2026-10-30 14:51:09 -06:00
Behdad Esfahbod ca538ba0d1 [ft] Preserve face and blob ownership through loader lifetimes (#6475)
Keep the memory-backed FT_Face blob on the hb_face_t even when the
OpenType sanitizer discards its copy. Otherwise the destroy callback
can release the FT_Face while the face or font still uses it. Return
the empty object on allocation failure before accessing that pointer.

Keep a blob loader's input bytes on the FT_Face rather than the
hb_face_t, since retained table blobs can outlive the latter. Keep the
library reference on the input blob and release it outside the static
FreeType mutex. Initialize file-loader ownership before transferring
references as well.

Add regressions for destroy-callback timing, referenced font lifetime,
and table blobs retained past the source face. All 293 tests pass,
including all eight FreeType subtests under ASan and UBSan. A separate
sanitized ownership probe passes 154 allocation-failure cases.

Discovered by Anthropic's OSS Scanner, as vulnerabilities
ANT-2026-FC0F75Y2 and ANT-2026-O2E5WAA5.

Assisted-by: OpenAI Codex
2026-10-30 14:49:21 -06:00
Behdad EsfahbodandClaude Opus 4.8 703509a9d9 [GPOS] Bound cross-offset resolution by the glyph count (#6492)
Cursive lookups with different flags can create an attachment cycle.
The const cross-offset walker then follows it forever when attaching
a mark. An acyclic chain over len glyphs has at most len - 1 links;
stop at that bound while retaining every valid forward and backward
chain and the existing offset accumulation behavior.

Add an in-house shaping regression instead of a bespoke unit test:
a tiny payload font whose two cursive lookups (one RightToLeft, one
IgnoreMarks) close an A -> B -> C -> A cycle, with a MarkBasePos that
attaches a mark onto C. Shaping ABCD looped forever before the fix and
now terminates. The original hang is reproduced on the unpatched tree;
the patched build shapes it identically under the ot and ft font-funcs.
The full Meson suite passes (274 tests), including shaping.

Reported by Anthropic's OSS Scanner as ANT-2026-PRD7EFA6.

Assisted-by: OpenAI Codex

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:48:18 -06:00
Behdad EsfahbodandClaude Opus 4.8 d5471c112c [set] Keep the set well-formed when growing it fails after compaction (#6495)
process_() moves the kept page_map entries to the front and renumbers
their pages with compact() before calling resize(count), which can fail
when the operation grows the set (passthru_right without passthru_left:
union with an inverted set, intersect of an inverted set, subtract of two
inverted sets). On failure the set kept its old page_map/pages length with
a duplicated, unsorted map; hb_bit_set_t::set() copied that state into a
fresh set that reported success, and a later del_range()/add() then indexed
pages out of bounds.

compact() already knows the kept length, so truncate page_map and pages to
it with shrink(length, false), which cannot fail. The set is now consistent
before any fallible growth, and del_pages() no longer needs its own resize()
after compact().

Only host programs doing mixed inverted/normal hb_set_t arithmetic under a
failing allocation reach this; HarfBuzz itself never runs the operation on a
non-empty left set, so it is an ordinary bug, not a security issue.

A regression test in src/test-set.cc simulates the allocation failure for
both process() and del_range() and checks the resulting lengths and map.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-LG3UXUGW.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:46:10 -06:00
Behdad EsfahbodandClaude Opus 4.8 f69c05ea38 [cairo] Map non-monotone buffer clusters to one cairo cluster
hb_cairo_glyphs_from_buffer() asserted that buffer clusters are monotone
in the buffer direction, but hb_shape() does not guarantee that:
HB_BUFFER_CLUSTER_LEVEL_CHARACTERS, shaping that hits the ops limit
mid-lookup, and Indic reordering corner cases can all produce
non-monotone clusters.  The function runs from HarfBuzz's own cairo
text_to_glyphs callback on attacker-controlled text and fonts, so the
assertion was an input-dependent abort (and, with NDEBUG, an unchecked
backward walk off the ends of the utf8 buffer).

The cluster-counting loop that already walks the buffer now detects a
step against the buffer's direction and falls back to a single cairo
cluster mapping all of the utf8 to all of the glyphs, which cairo
accepts.  The monotonicity assertions in the fill step then hold by
construction and glyph output is unchanged for monotone buffers.

A regression test in test/api/test-cairo.c feeds monotone and
non-monotone LTR/RTL buffers through both cluster modes and checks the
cluster counts and byte/glyph totals; it aborts on the pristine tree.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-T4PZ1H72.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:45:15 -06:00
Behdad EsfahbodandClaude Opus 4.8 4e215a7ec8 [cairo] Don't leak the hb_font_t created per scaled font
hb_cairo_init_scaled_font() must hand exactly one reference of the
hb_font_t to the cairo_scaled_font_t.  For a face-based font face
(hb_cairo_font_face_create_for_face()) it creates the font with a
reference count of 1, but then still called hb_font_reference() before
attaching it, so the creating reference was never released.  Every
finalized scaled font therefore leaked an hb_font_t, pinning its
hb_face_t, the font blob and the accelerators until the process exits.
Cairo finalizes scaled fonts during normal operation once its cache
fills, so the leak accumulates as content selects distinct sizes,
transforms or font options.

Take the extra reference only in the branch where the font is the
shared one owned by the cairo font face (the font-based constructor),
and transfer the freshly created font as-is.  The set_user_data result
is now checked and the font released on failure, matching the
budget/color-cache idiom a few lines below and the font-face
constructors in the same file.

A callback installed with hb_cairo_font_face_set_font_init_func() that
returns a different font keeps its historical behavior: the returned
font is referenced rather than assumed to transfer ownership, so no
in-tree contract changes and no caller can turn into a use-after-free.
hb-view uses the font-based constructor and was unaffected.

A regression test in test/api/test-cairo.c registers a face destroy
notifier, draws through a face-based font face, flushes cairo's
scaled-font cache and asserts the face was destroyed; it fails on the
unpatched library and passes with the fix.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-BAUN9JN4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:44:32 -06:00
Behdad EsfahbodandClaude Opus 4.8 fd8c9209b6 [cairo] Paint nested color glyphs inline to bound recursion
hb_cairo_paint_color_glyph() accepted the color_glyph paint callback
and drew the nested glyph with cairo_show_glyphs(), which re-enters
hb_font_paint_glyph() through a new cairo scaled font with a fresh
hb_paint_context_t.  The glyph decycler, HB_MAX_NESTING_LEVEL and the
edge budget therefore start over at every level, so two glyphs that
paint each other with PaintColrGlyph recurse until the stack is
exhausted.  The per-scaled-font hb_cairo_budget_t cannot bound this
either: the nested glyph is shown through a different scaled font, so
each level gets its own budget.

Decline the callback, returning false exactly as hb-raster's does, so
the COLR (and hb-ft-colr) walk paints the nested glyph inline under the
decycler and depth limits of the walk already in progress.

A regression test with two PaintColrGlyph glyphs that paint each other
is added to test/api/test-cairo.c; it aborts on the unpatched library
and passes with the fix.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-VPKA505E.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:43:49 -06:00
Behdad Esfahbod 88e5077a80 [aat] Read kerx format 2 class values as byte offsets (#6494)
Format 2 class values are byte offsets, but ExtendedTypes::offsetToIndex
leaves them unchanged. Use byteOffsetToIndex to convert their sum to an
FWORD index. ObsoleteTypes retains the existing kern format 2 behavior.

Add a synthetic font and shaping regressions covering negative and
positive kerning, the final array entry, zero classes, missing lookup
entries, and disabled kerning.

The shaping regression fails without the fix. The full Meson test suite
passes, and Helvetica Light's LY, AY, Hi, and HH kerning matches CoreText.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6461
Assisted-by: OpenAI Codex
2026-10-30 12:49:31 -06:00
Behdad Esfahbod 6156c7b4a7 [subset] Validate custom glyph mappings before assigning output ids (#6479)
Glyph zero is always reserved for .notdef. Reject mappings that assign
another retained glyph to it, so the output list has one entry per id.

Also bound the resulting glyph count by the widest supported count
field, MAXP's HBUINT24. Account for the unmapped glyphs and the initial
slot before assigning ids, avoiding wraparound and oversized counts in
table subsetters. The limit applies to the count, not the highest id.

Document these constraints and test valid renumbering, gaps, ignored
remapping of .notdef, reserved-id collisions, and out-of-range counts.
The regression and stock hb-subset both reproduce the issue under ASan
before the fix. All 293 tests pass after it, including the subset suite;
the API subset tests and command-line checks also pass ASan and UBSan.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-6I1RIFMQ.

Assisted-by: OpenAI Codex
2026-10-29 21:01:05 -06:00
Behdad Esfahbod d8347f079e [repacker] Count null offsets when splitting ligatures (#6476)
Ligature split points skipped null offsets while the ranges used to
clone and shrink subtables counted every slot. Advance the split index
for null offsets too, so both stages refer to the same ligatures.

Also reject an inverted range after narrowing it to the remaining
links, before calculating the number of ligatures to allocate.

Add a regression that compares the split graph with the expected
subtables when one ligature set has trailing null offsets.

Testing: meson test -C build (292 passed; check-symbols skipped on
macOS), plus the repacker test and shared-ligature font check with
ASan and UBSan.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-9C9WB0KM.

Assisted-by: OpenAI Codex
2026-10-29 21:00:03 -06:00
Behdad Esfahbod 8f115ee233 [vector] Keep allocation capacity representable as an int (#6484)
Reject allocation requests above INT_MAX before growing the capacity,
and cap geometric growth at that limit. Otherwise the unsigned growth
loop can wrap, or a successful allocation can store a negative value
in the signed capacity field. Normalize exact requests before checking
the limit so the existing length is included.

Test both normal and exact oversized requests, preservation of existing
contents on failure, and saturation of geometric growth. Intercept the
allocator in the unit test to avoid allocating large buffers. The new
regression fails before the fix. All 293 tests pass, and test-vector
passes under ASan and UBSan.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-N6HMDRS8.

Assisted-by: OpenAI Codex
2026-10-29 20:58:54 -06:00
Behdad Esfahbod 4aebec5702 [subset/cff1] Bound preprocessing map lookups for output gaps (#6481)
A custom glyph mapping can leave unassigned output glyph IDs beyond
the source glyph count. The preprocessing glyph-to-SID map only covers
source glyphs, so use the existing charset lookup for those gaps and
skip the map-based range shortcut there.

Compare plain and preprocessed subsets of existing name-keyed and
CID-keyed fonts with output gaps. The new regression fails under ASan
before the fix. The complete ASan/UBSan Meson suite passes afterward
(293 tests, including 23 CFF1 API subtests).

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-42ZOI3TR.

Assisted-by: OpenAI Codex
2026-10-29 20:57:13 -06:00
Behdad Esfahbod 21a2f7c43e [repacker] Reject output sizes that cannot fit a blob (#6478)
The graph total is size_t, while the output vector allocation takes an
unsigned int. Check the total against the blob length limit before that
conversion, so the allocation and serialization context use the same
size. Totals above INT_MAX cannot produce a valid output blob anyway.

Add a public-API regression whose objects share their backing storage,
keeping its memory use small while exercising a large graph total.

Testing: meson test -C build (292 passed; check-symbols skipped on
macOS), plus test-subset-repacker with ASan and UBSan. The regression
reproduces the invalid write without the check and fails cleanly with it.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-4Q0YO46E.

Assisted-by: OpenAI Codex
2026-10-29 20:56:03 -06:00
Behdad Esfahbod fdd29aa9a9 [subset] Check the VARC axis-index allocation size before narrowing (#6477)
The saturating size helper returns size_t, so assigning its product to
unsigned can truncate it before the UINT_MAX check. Check multiplication
at unsigned width before resizing the buffer used by compile_unsafe().

Validated the reported high-count case under ASan/UBSan: it fails cleanly
after this change. A small control produces byte-identical output. The
ASan/UBSan Meson suite passes; check-symbols also passes after generating
its symbol manifests.
The large input remains a manual regression because it requires several
GB of memory.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-V0UYCX4C.

Assisted-by: OpenAI Codex
2026-10-29 20:55:45 -06:00
Behdad Esfahbod d0b38a793b [arabic-fallback] Count components only for matched ligatures (#6474)
A missing component skipped a fallback ligature but left its partial
component list counted. Later ligatures then used the wrong letters.
Write tentative components at the current offset and advance the
count only after every component has matched.

Add a generated GSUB-less font and two shaping regressions, covering
both the wrong ligature and the valid ligature it displaced, with ot
and ft font functions. All four cases fail before the fix. The full
Meson suite passes (293 tests, 6227 in-house shaping subtests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-EMRGZ57Y.

Assisted-by: OpenAI Codex
2026-10-29 19:31:29 -06:00
Behdad Esfahbod ecf0bc81aa [subset] Keep ClassDef range traversal in sync for class zero (#6473)
The class-zero intersection loop skipped ranges starting at glyph 0
without advancing the last glyph, and consulted a separate iterator
instead of the range being visited. Probe only actual gaps and always
advance past each range, so unlisted glyphs retain class-zero rules.

Check all 256 glyph sets over eight glyphs against per-glyph class
lookup for empty, contiguous, gapped, and explicit class-zero ranges.
The regression fails on the old source. The full Meson suite passes
(293 tests), including shape and subset.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-K9HEP9ZU.

Assisted-by: OpenAI Codex
2026-10-29 19:30:56 -06:00
Behdad Esfahbod 90045a6551 [vector] Use font coordinates for PDF draw page bounds (#6472)
The PDF draw renderer emitted paths in Y-up coordinates but vertically
mirrored the MediaBox and background rectangle. Use the same extents
for the content, page, and background, matching the paint renderer.

Regenerate the existing PDF fixture with hb-vector. Only the page box
and background coordinates change. Its page now covers the glyphs'
outline Y range; the old page did not. The updated vector regression
fails on the old source. The full Meson suite passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-0ER2GEWZ.

Assisted-by: OpenAI Codex
2026-10-29 19:30:02 -06:00
Behdad Esfahbod 3c0e2b42d5 [vector] Keep SVG path clips in the body's coordinate space (#6471)
The SVG body is flipped from font coordinates once at render time.
The path-clip callback still emitted its own vertical flip from the
older renderer, mirroring the clip relative to the drawing. Remove
that transform, matching rectangle and glyph clips.

Add a paint/show-extents vector regression and generate its expected
SVG with hb-vector. It fails on the old code. The full Meson suite
passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-BZKWFGVZ.

Assisted-by: OpenAI Codex
2026-10-29 19:29:29 -06:00
Behdad Esfahbod f030bd2186 [ot-layout] Convert script tags for hanging baseline synthesis (#6467)
The baseline fallback accepts an OpenType script tag but compared it
with hb_script_t values. Convert the tag before choosing the glyph
used to synthesize the hanging baseline.

Exercise Bengali's old and new OpenType tags, Tibetan, and the script
and language entry point. The updated test fails before the fix
(622 versus 600); the full Meson suite passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-COIT72UF.

Assisted-by: OpenAI Codex
2026-10-29 19:28:41 -06:00
Behdad Esfahbod c207662595 [var] Keep intermediate tuples out of the shared-scalar cache (#6468)
* [var] Recalculate intermediate tuples with a cached zero scalar

The shared-tuple scalar cache describes the default region around a
shared peak. An intermediate region can extend beyond that peak, so a
cached zero need not mean its own contribution is zero. Only reuse a
cached one for intermediate tuples; otherwise evaluate their region.

Check cached and uncached results across the axis range and in both
tuple evaluation orders. The regression fails before the fix. The
full Meson suite passes (293 tests), including the shape suite.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-RTBS23VC.

Assisted-by: OpenAI Codex

* [var] Drop cache reuse for intermediate tuples

Keep the plain shared-tuple cache fast path and remove the secondary
probe for intermediate tuples. Evaluate their own regions and disable
cache writes before the axis loop, including at exact peak locations.
This also removes the redundant per-axis cache-pointer reset.

The full Meson suite passes (293 tests), including the cache regression
and the shape and subset suites.

Follow-up for ordinary bug ANT-2026-RTBS23VC.

Assisted-by: OpenAI Codex
2026-10-29 19:27:07 -06:00
Behdad Esfahbod df19e5053b [raster] Keep the interior of transformed rectangle clips (#6470)
The point-in-quad test rejected the interior side of each edge for
both winding orders. Reverse the comparisons for rectangle and mask
intersections, and clarify how the edge normal depends on winding.

Add a regression for skew, reflected skew, and rotation, with one or
two nested rectangle clips to exercise both intersection paths. The
center pixel was transparent before the fix. The full Meson suite
passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-AM92X98M.

Assisted-by: OpenAI Codex
2026-10-29 19:07:51 -06:00
Behdad Esfahbod be6b6ab2b5 [subset] Use outline bounds for instanced CFF2 metrics (#6469)
The bounds vectors used to rebuild hhea and vhea expect non-negative
widths and heights, with a sentinel for glyphs without outlines.
CFF2 instancing stored negative extents.height values and replaced the
sentinel for empty glyphs. Store yMax - yMin and preserve empty bounds.

Regenerate the three affected expected fonts through the subset test
generator. Only header metrics and checksums change. The new vhea
values agree with FontTools recalculation from the glyph outlines.
Both affected test cases fail without the source fix; the full Meson
suite passes with it (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-3LQ6CVVN.

Assisted-by: OpenAI Codex
2026-10-29 19:07:27 -06:00
Behdad Esfahbod 879be16fdf [ot-metrics] Use the vertical descender in the fallback (#6466)
Fonts without vhea returned the ascender for the vertical descender
metric. Read the descender from the synthesized vertical font extents,
as the horizontal fallback already does.

Add a regression comparing all three fallback vertical metrics with
the font extents. It fails before this change (1024 versus -1024).
The full Meson suite passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-4UNO2SK8.

Assisted-by: OpenAI Codex
2026-10-29 18:52:24 -06:00
Behdad Esfahbod 1e6a7f38ee [cff] Reject INDEX item counts that do not fit (#6465)
CFF1 INDEX counts are 16-bit. Serializing a larger iterator truncated
its count before reserving the offset array, then wrote offsets for
every item. Check the count before allocating or writing the offsets.

Test the CFF1 boundary and the corresponding valid CFF2 counts, and
reject a subset glyph mapping that overflows the CharStrings INDEX.
Both regressions fail before this change. The full Meson suite passes
(293 tests), including the subset and API suites.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-8ROS1VQ9.

Assisted-by: OpenAI Codex
2026-10-29 18:31:46 -06:00
Behdad Esfahbod cd4d7664e1 [test] Avoid Windows small macro in raster paint test
Windows headers define small as char, so the local extent variable
breaks compilation in both MSVC CI configurations. Rename it to
small_extents.

Reproduced the failure with the macro defined and verified that the
same compilation succeeds after the rename. The MinGW cross-compiler
syntax check and full Meson suite pass (274 tests).

Assisted-by: OpenAI Codex
2026-10-29 16:15:21 -07:00
Behdad Esfahbodandnussaiba shaikh 404378164a [raster] Keep paint surfaces and budgets tied to the active root (#6464)
Changing extents during painting could allocate small group surfaces
against the original root and clip, causing out-of-bounds reads and
writes. Keep all session surfaces at the root's extents.

Use the same extents for group clear charges and pixel budget
recharges, so changing the configured rectangle cannot undercount
work on the active image. Document that render clears extents rather
than deferring a mid-session change to the next image.

Adapt the pixel regression from #6450 and check the render lifecycle.
Add an internal test for new and cached group clear charges and
budget recharging, using small buffers.

Reproduced the heap overflow on main under ASan. The budget test
fails with #6450. With this change, both raster test targets pass
under ASan+UBSan and the full Meson suite passes (274 tests).


Assisted-by: OpenAI Codex

Co-authored-by: nussaiba shaikh <nussaibah@bugqore.com>
2026-10-29 17:04:03 -06:00
Behdad Esfahbodandnussaiba shaikh d19879d033 [font] Clamp scaled glyph extents using stored bearings
Saturated int32 extents can round up to 2^31 when converted to float.
Clamp each scaled field before converting back to hb_position_t.
Compute width and height in double relative to the stored, clamped
bearings, preserving the existing formulas when a bearing saturates.

Adapt the COLR clip-box regression from #6459 and cover positive and
negative scales. At default scale, rounding INT32_MAX up to 2^31
leaves a one-unit extent relative to the clamped bearing.

Reproduced the original float-cast-overflow under UBSan. After the
fix, the color, extents, and font-scale API tests pass under UBSan,
and the full Meson test suite passes (273 tests).

Co-authored-by: nussaiba shaikh <nussaibah@bugqore.com>
Assisted-by: OpenAI Codex
2026-10-29 15:42:53 -07:00
Behdad Esfahbod a6214eefde [subset] Propagate CFF1 encoding range overflow errors
Returning false without setting a serializer error treats the CFF
subset as empty and silently drops its outlines. Record an error when
format 1 needs more than 255 encoding ranges so subsetting fails.

Reuse the many-codes fixture to check that 255 ranges still succeed
and 256 ranges fail. The regression fails before the fix.

Testing: meson test -C build (273 passed).

Assisted-by: OpenAI Codex
2026-10-29 15:35:51 -07:00
Beleniuc Ilie 4868fd314f [subset] Use CFF1 Encoding format 1 for more than 255 codes (#6460)
A format 1 Encoding can give codes to more than 255 glyphs, since
codes may repeat across ranges. When the subset keeps more than 255
of those glyphs, as with retain-gids, plan_subset_encoding() hit
assert (subset_enc_num_codes <= 0xFF).

Choose format 0 only when it can hold the codes, and fail cleanly in
the format 1 serializer instead of truncating nRanges past 255.

Add a test font whose format 1 Encoding covers 768 glyphs, and the
reporter's font to the fuzzing corpus.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6031
Assisted-by: Claude
Assisted-by: OpenAI Codex
2026-10-29 16:35:22 -06:00
Behdad Esfahbod c305720f01 [subset] Handle seac operands returned by a subroutine (#6463)
A subroutine can push all four seac operands, return, and leave the
glyph's own endchar to consume them. Treat callsubr and callgsubr
immediately before endchar as possible seac suffixes even when no
subroutine contains endchar.

Add a synthetic CFF1 regression font for the operand-only subroutine
case.

Assisted-by: OpenAI Codex
2026-10-29 16:25:35 -06:00
Behdad Esfahbod 2c0df50ce1 [subset] Make CFF1 seac precheck conservative (#6458)
A subroutine can terminate a glyph with endchar, and dotsection preserves
live operands. Account for both cases when deciding whether a CFF1
charstring can form a seac composite.

Cache whether any subroutine may contain endchar so ordinary fonts keep
the fast trailing-byte check. Skip component closure when all glyphs are
already retained, except when computing reusable accelerator metadata.

Add regressions for endchar in a local subroutine and operands preserved
across dotsection.

Assisted-by: OpenAI Codex
2026-10-27 18:05:47 -06:00
Behdad Esfahbod b6bc4e1650 [subset] Reuse identity CFF1 program bytes (#6457)
After computing subroutine closure, reuse source charstrings and
subroutines when every retained subroutine keeps its original number.
This avoids re-encoding full identity CFF1 subsets while preserving
the existing pruning behavior when any subroutine is unused.

The full Meson test suite passes (295 passed, 1 skipped).

Assisted-by: OpenAI Codex
2026-10-27 15:50:48 -06:00
Behdad Esfahbod f306676520 [subset] Tighten CFF2 absolute rounding (#6443)
Clear flex-depth deltas when they all round to zero and reject unexpected
operators in the absolute-rounding pass. Cover static fractional operands
in a charstring that also contains blends.

Remove command-capture branches made redundant by the full-instancing
control flow.

Testing: meson test -C build (295 passed, one skipped).

Assisted-by: OpenAI Codex
2026-10-27 15:42:35 -06:00
nussaibah shaikh 6c8fe9f278 [aat] Don't divide by zero interpolating duplicate trak tracks (#6425)
* Don't divide by zero interpolating duplicate trak tracks

TrackData::get_tracking() brackets the requested track value (always
0 when shaping) between entries i and j and interpolates with
(track - t0) / (t1 - t0).  The bracketing scan doesn't assume the
entries are sorted or distinct, so two entries that both have track
value 0.0 end with i = 1, j = 0.  That skips the exact-match return
and computes 0/0.  The NaN reaches hb_font_t::em_multf(), where the
cast to hb_position_t is undefined (UBSan float-cast-overflow at
hb-font.hh:1167); in practice the advance becomes INT_MIN on x86 and
the tracking is dropped on arm64.

Sanitize accepts such a table, so any font with STAT plus this trak
reaches it from hb_shape(); the CoreText font funcs call the same
getter.

Handle t0 == t1 the way TrackTableEntry::interpolate_at() already
handles equal sizes, by averaging the two values.

Added a 108-byte font to the aat-trak shape tests.  It fails without
the fix and passes with it.  meson test passes on an ASan+UBSan
debug build.

Assisted-by: Claude

* [aat] Pin duplicate-trak test to ot font funcs

The 108-byte test font only carries STAT and trak, with no head,
hhea or hmtx.  The ot font funcs give each glyph a 500 advance, but
FreeType reports 1000 and DirectWrite refuses to load the font, so
the ft and directwrite runs of the test disagreed with the expected
output.  The test only needs to exercise the trak interpolation,
so pin it to --font-funcs=ot like other minimal-font tests.

Tested with meson test -C build; the shape suites pass with
FreeType enabled.

Assisted-by: Claude
2026-10-27 14:44:18 -06:00
ebraminio 068e3dfa96 Merge pull request #6444 from ebraminio/hb-number-parser
[number] Remove extra buffer of parse_bcd while parsing
2026-10-27 14:43:45 -06:00
Behdad Esfahbod 4e477213af [depend] Read 24-bit coverage offsets in ContextFormat3_6::depend (#6455)
[depend] Read 24-bit coverage offsets in ContextFormat3_6::depend
2026-10-27 14:41:46 -06:00
Behdad Esfahbod d58303f500 [subset] Choose the smallest CFF charset format (#6456)
Split long CFF charset runs into format 1 chunks and compare the
resulting size with formats 0 and 2. Previously, any run longer than
256 glyphs forced all ranges to format 2.

This reduces the CFF table for NotoSansSC-Thin.otf by 13,938 bytes
without changing decoded table contents.

Assisted-by: OpenAI Codex
2026-10-27 14:39:02 -06:00