Commit Graph
16700 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Fable 5 f6bcedab83 [subset/cff] Record byte segments instead of tokens when not analyzing hints
The CFF subroutine subsetter recorded one parsed_cs_op_t entry per
charstring token (every operand and operator), then merged adjacent
entries back together in a separate compact() pass.  When hints are
not being analyzed (not dropping hints and not populating the subset
accelerator), per-op granularity is never needed: the only structure
that matters is the subroutine-call sites, whose numbers are
re-encoded with new biases.

In that mode, only note token boundaries (two integer stores) and
flush verbatim byte segments at call sites and at the end of each
string.  CFF1's return/endchar bytes flush through add_op; CFF2 has
no such ops in the stream, so flush explicitly where the interpreter
synthesizes them at end-of-string.  This eliminates the compact()
pass, shrinks the parsed representation by an order of magnitude,
and add_op inlines into the interpreter loop again.

Speeds up CFF subsetting: hb-subset on SourceHanSans (10K glyphs,
all unicodes) improves by ~9.5% total CPU (interleaved A/B against
main with perf stat).  Layout-heavy and glyf fonts unaffected.

Tested with meson test (all 267 tests pass, including CFF1/CFF2
golden-file subset comparisons).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 05:21:02 -06:00
Behdad EsfahbodandClaude Fable 5 7990062241 [subset] Remap Coverage glyphs through a flat array
Coverage::subset remapped every covered glyph through the
glyph_map_gsub hash map, paying a hash lookup per glyph.  Build a flat
old-gid-indexed array of new gids (HB_MAP_VALUE_INVALID holes for
unretained glyphs) once per plan, sized to the highest retained GSUB
gid, and index it instead.  The array doubles as the retained-glyph
filter, and the lambda mapper also inlines into the iterator pipeline
where the hb_map_t mapper did not.

Speeds up subsetting layout-heavy fonts: benchmark-subset
subset_unicodes on NotoNastaliqUrdu at 512 codepoints improves by 12%
(26.2ms to 22.9ms), Amiri at 512 by 9%.  No measurable change on
small subsets or glyf-heavy CJK fonts.

Tested with meson test (all 267 tests pass).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 05:21:02 -06:00
Behdad Esfahbod cb9460bcbb Merge pull request #6185 from harfbuzz/agent/depend-context-memoization
[depend] Speed up contextual dependency collection
2026-08-20 05:20:24 -06:00
Behdad EsfahbodandClaude Fable 7c349a3f89 [depend] Ignore edge flags in recursion memoization
Edge flags affect neither traversal nor edge identity. A state revisited
with different flags can therefore only attempt edges already present in
the deduplication table, whose first-discovered flags already win. Leave
context-set identity in the key because it does distinguish edges.

This reduces Noto Nastaliq dependency construction from about 110ms and
1.25B instructions to about 106ms and 1.21B instructions.

Dependency graphs match on Noto Nastaliq, Noto Sans Duployan, Gulzar,
Iran Nastaliq, Noto COLRv1, Amiri, and Source Serif Variable.

Tested with: meson test -C build

Co-Authored-By: Claude Fable <noreply@anthropic.com>
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:53:24 -06:00
Behdad EsfahbodandClaude Fable 8d0b8738ab [depend] Skip cached chained-context preparation
A chained contextual rule with cached record labels no longer needs to
rebuild its backtrack, lookahead, or input-position sets. Reuse the
resolved labels and recurse directly.

Do not take the fast path for rules with no valid lookup records. Those
rules have no label-cache entries, but their original preparation can
still allocate dependency sets in an observable order.

On Noto Nastaliq, compile-only dependency construction falls from about
133ms and 1.58B instructions to about 110ms and 1.25B instructions.
That is about 4,237x faster than the original 7:44.77 run.

Dependency graphs match on Noto Nastaliq, Noto Sans Duployan, Gulzar,
Iran Nastaliq, Noto COLRv1, Amiri, and Source Serif Variable.

Tested with: meson test -C build

Co-Authored-By: Claude Fable <noreply@anthropic.com>
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:47:15 -06:00
Behdad Esfahbod 980cceb98e [depend] Reuse cached context label lookups
The all-cached precheck already resolves every context-set index, but
the recurse loop looked up each key a second time. Retain those indices
in per-depth scratch storage and consume them directly on the cached
path.

On Noto Nastaliq this reduces compile-only construction from about
136ms to about 133ms while preserving byte-identical graph output.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:39:44 -06:00
Behdad Esfahbod 75455f7338 [depend] Skip cached contextual input expansion
Once every lookup record's context label is cached, the expanded input
position glyph sets are no longer consumed. Check the exact label keys
first and bypass that side-effect-free preparation on a full cache hit.

Keep chained backtrack and lookahead set interning in place because its
allocation order determines observable dependency-set indices.

On Noto Nastaliq, compile-only dependency construction falls from about
151ms and 1.87B instructions to about 136ms and 1.59B instructions. The
original 7:44.77 run is now about 3,420x slower.

Dependency graphs match the pre-change output for Noto Nastaliq,
Noto Sans Duployan, Gulzar, Iran Nastaliq, Noto COLRv1, Amiri, and
Source Serif Variable.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:36:35 -06:00
Behdad EsfahbodandClaude Fable 63b41dab9f [depend] Cache contextual edge labels
Contextual rules rebuild the same position-specific context label for
each visit even though it depends only on the rule, lookup record, and
parent active glyph contents. Intern active glyph sets across top-level
lookups and cache the resulting context-set index by that stable
identity.

This avoids repeated set scans, intersections, and content hashing
without changing traversal or label semantics. On Noto Nastaliq,
compile-only dependency construction falls from about 209ms and 2.77B
instructions to about 151ms and 1.87B instructions. That is about
3,080x faster than the original 7:44.77 run.

Dependency graphs match the pre-change output for Noto Nastaliq,
Noto Sans Duployan, Gulzar, Iran Nastaliq, Noto COLRv1, Amiri, and
Source Serif Variable.

Tested with: meson test -C build

Co-Authored-By: Claude Fable <noreply@anthropic.com>
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:27:07 -06:00
Behdad Esfahbod 3a1ab8f173 [depend] Compact edge deduplication storage
Dependency edges are already retained in per-glyph output vectors, but the
generic deduplication hashmap stored another complete edge record in every
36-byte bucket. Replace it with an exact open-addressed table whose buckets
hold only an eight-byte source and per-glyph edge index. Hash collisions are
resolved by comparing the retained records, preserving first-seen ordering
and flags.

On Noto Nastaliq this reduces construction from about 229ms to 209ms and
from 2.83 to 2.77 billion instructions. Peak RSS falls from about 46MB to
28MB, while cumulative allocated bytes fall from about 78.4MB to 49.1MB.

Dependency graphs match for Noto Nastaliq, Noto Sans Duployan, Gulzar,
Iran Nastaliq, Noto COLRv1, Amiri, and Source Serif Variable Roman.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:16:51 -06:00
Behdad Esfahbod 5bf0cfbc45 [set] Insert coverage intersections by bitmap word
Coverage format 2 now reads intersection results a word at a time, but
still inserted every selected glyph separately. Add an internal
word-at-a-time set insertion path and use it when the output sink is an
hb_set_t, preserving the generic per-glyph fallback for other sinks.

This removes another about 121M instructions from Noto Nastaliq
dependency construction. The compile-only run now takes about 226ms
task-clock / 229ms elapsed and 2.83B instructions, over 2,000x faster
than the original 7:44.77 run.

Dependency graphs match the original output for Noto Nastaliq, Noto
Sans Duployan, Gulzar, Iran Nastaliq, Noto COLRv1, Amiri, and Source
Serif Variable Roman.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:04:54 -06:00
Behdad Esfahbod f3a00d0086 [set] Intersect coverage ranges by bitmap word
Coverage format 2 previously advanced the input set one glyph at a time
inside each coverage range. Fetch nonempty 64-bit words instead, mask the
boundary words, and consume their bits locally.

This removes about 96M instructions, or 3.2%, from Noto Nastaliq
dependency construction. Dependency graphs match the previous output
across Noto Nastaliq, Duployan, Gulzar, Iran Nastaliq, Noto COLRv1,
Amiri, and Source Serif Variable.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:00:24 -06:00
Behdad Esfahbod 7951998565 [set] Compute iterator length lazily
Set iteration does not always need the remaining item count. Defer the
population scan until len() is first requested, using unsigned accounting
to track advances without adding a branch to the iterator hot path.

This preserves fast length for iterator consumers that use it while
avoiding unnecessary population scans for the others. Noto Nastaliq
dependency construction is instruction-neutral because its existing set
iterators already encounter cached populations.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:55:41 -06:00
Behdad Esfahbod 375b3f4b33 [depend] Combine edge deduplication lookup and insert
Use a non-overwriting hashmap insertion to detect duplicate dependency
edges. This avoids hashing and probing every newly inserted edge twice,
while still distinguishing duplicates from allocation failures through
the hashmap error state.

The NotoNastaliqUrdu compile-only dependency workload saves about 2.2M
instructions. Its wall-time change is below measurement noise.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:48:08 -06:00
Behdad Esfahbod 4daafa0767 [depend] Encode common active glyph states
Root and singleton active-glyph sets dominate dependency recursion memo
keys. Avoid copying and interning the root set, and encode singleton glyph
IDs directly in the key.

Add an internal singleton query that can recognize uncached sparse sets in
one pass while preserving the population cache.

On NotoNastaliqUrdu-Regular.ttf this reduces the compile-only dependency
run from about 3.18B to 3.05B instructions and from about 245ms to 238ms.
Dependency graphs match the previous output across the focused font
corpus.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:45:19 -06:00
Behdad Esfahbod 772005ba59 [depend] Intern recursion paths directly
Memoization previously interned the full set of in-progress lookups for
every recursive dispatch.  Hashing, comparing, and copying those sets
became visible after the larger dependency-analysis speedups.

Assign stable IDs to ordered recursion paths instead.  The path identity
is conservatively more specific than lookup-set identity, while the
separate bit set continues to provide exact cycle detection.

This reduces Noto Nastaliq dependency construction by about 4% in
instructions while preserving byte-identical graphs across the tested
font corpus.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:16:03 -06:00
Behdad Esfahbod c011af18b9 [subset] Use set iterators when formatting input
Walk tag sets and sorted glyph-map keys through their native iterators
instead of repeatedly calling the public scalar set API.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:48:34 -06:00
Behdad Esfahbod 3c55d48206 [set] Iterate over bitmap words
Fetch one nonempty 64-bit bitmap word at a time and consume its bits
locally in hb_set_t iterators. This avoids searching the sparse page
map once per codepoint while preserving inverted-set iteration and
bidirectional iterator behavior.

Mutating a set now explicitly invalidates its iterators.

Noto Nastaliq dependency construction is about 1-2% faster in an A/B
comparison, with 3.33B instructions reduced to 3.31B.

Tests: meson test -C build (272/272)
Tests: Noto dependency graph byte-identical to the pre-change oracle
Tests: full-Unicode subset output byte-identical for Noto Nastaliq,
       Amiri, Source Serif Variable, and Noto COLRv1

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:45:18 -06:00
Behdad Esfahbod 31d8ff343e [depend] Flatten lookup feature storage
The per-lookup nested feature vectors introduced a leak in the sanitizer
job: their inner allocations were lost when the temporary dependency
builder was destroyed on GitHub's Clang 18 build.

Pack lookup index and feature tag into a single flat uint64_t vector, then
sort and deduplicate it and build per-lookup offsets. This preserves the
compact sequential traversal and its performance while giving the builder
only flat owning containers.

Tests: meson test -C build (272/272)
Tests: Clang 18 ASan/UBSan depend-fuzzer chunks (9/9)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:33:15 -06:00
Behdad Esfahbod b3eb3329d2 [depend] Store lookup feature tags in vectors
Lookup feature tags are collected once, then only iterated while dependency
edges are emitted. Sparse sets make each of those tiny iterations pay bit-page
lookup costs in a major graph-construction hot path.

Append tags to per-lookup vectors, then sort and deduplicate each vector once
after collection. This preserves the set's sorted iteration order while
avoiding quadratic insertion behavior for pathological feature lists.

On Noto Nastaliq this reduces dependency compilation from about 275ms to
259ms, with instructions falling from 3.50 billion to 3.32 billion. Output
is byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:09:19 -06:00
Behdad Esfahbod 87f696af11 [set] Make intersection workspace optional
Pass reusable intersection workspace as an optional pointer through the set
layers. Existing callers keep the ordinary local-workspace behavior, while
hot paths can opt into retaining the temporary allocation.

This also lets dependency position collection supply workspace only for the
class/parent intersection that can actually require compaction.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:09:19 -06:00
Behdad Esfahbod b3f9708a1e [set] Allow reusing intersection workspace
Removing pages during a bit-set operation needs a temporary index vector.
The normal set API allocates this vector locally so arbitrary callers do not
carry extra storage, but dependency traversal performs the same class-set
intersection hundreds of thousands of times.

Add an internal intersection overload that accepts caller-owned workspace,
and retain that workspace in the contextual recursion scratch pool. The
ordinary intersection path and its exact-sized temporary remain unchanged.

On Noto Nastaliq this removes 271 thousand allocation calls, reducing the
post-stack-reuse total from 371 thousand to 100 thousand. Compilation time
improves slightly from about 277ms to 275ms, and output is byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:55:02 -06:00
Behdad Esfahbod 8940e7050b [depend] Retain active glyph set storage
Dependency recursion moves each position glyph set onto the active stack.
Popping the stack then destroys the set and its backing pages, so the next
edge has to allocate them again.

Keep constructed stack slots and track the active depth separately. Reused
slots are cleared before use, preserving the previous empty-set semantics
while retaining their allocations across sibling traversals.

After contextual scratch pooling, this reduces Noto Nastaliq dependency
compilation from about 294ms to 277ms. Allocation calls fall from 1.19
million to 371 thousand, and cumulative allocated bytes fall from 163MB
to 80MB. Serialized output remains byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:49:31 -06:00
Behdad Esfahbod de89b1a490 [depend] Reuse contextual recursion scratch storage
Contextual dependency traversal repeatedly constructs temporary glyph sets
and pointer vectors. On Noto Nastaliq this causes over five million
allocation or reallocation calls even after recursion memoization.

Keep one scratch bundle per active contextual recursion level and recycle it
across sibling traversals. This retains backing capacity while preserving
the independent state needed by nested lookups.

For NotoNastaliqUrdu-Regular.ttf, dependency compilation drops from about
374ms to 294ms. Allocation calls drop from 5.26 million to 1.19 million,
and cumulative allocated bytes drop from 480MB to 163MB. Output is
byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:44:31 -06:00
Behdad Esfahbod f454a49034 [depend] Keep covered context positions inline
Contextual dependency traversal uses a set to track sequence positions
already covered by earlier lookup records.  Those positions are bounded
by HB_MAX_CONTEXT_LENGTH, but the general sparse set allocates its first
bit page on every contextual rule.

Use one inline hb_bit_page_t for dependency traversal.  Its 512 bits are
well above the configured 64-position context limit.  This reduces quiet
Noto Nastaliq graph construction from 385ms to 363ms.

Tested with the full Meson test suite (272/272 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:06:37 -06:00
Behdad Esfahbod 5aa7a80aa5 [depend] Cache contextual position glyph sets
Dependency graph extraction repeatedly expands identical class
definitions and coverages into temporary sets while traversing
contextual rules.  It also repeatedly interns those same sets when
recording context requirements.

Cache immutable position sets by source identity, reuse their context
set indices, and pass pointers through the short-lived position vectors
instead of copying their contents.  This reduces quiet Noto Nastaliq
graph construction from 685ms to 385ms on the profiling machine while
preserving the graph byte-for-byte.

Tested with the full Meson test suite (272/272 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 00:56:25 -06:00
Garret Rieger f7cef099e1 Fix potential divide by zero in apply_stch(). (#6186)
The product of n_copies * n_repeating can plausibly overflow uint32_t bounds leading to a divide by zero. Cast the values up to int64_t for the multiplication to prevent overflow. Otherwise both n_copies and n_repeating are guaranteed to be non-zero
2026-08-19 16:43:08 -06:00
Behdad Esfahbod 5e75e91ebf [set] Add hb_set_intersects API
Expose the exact set-intersection query so callers can test whether two
sets have any elements in common without copying and mutating a set.
The implementation handles inverted sets through the internal helper.

Document the new API with its release placeholder, add it to the docs
section index, and cover regular and inverted set combinations.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 16:00:05 -06:00
Behdad Esfahbod 80529ca839 [set] Add exact set intersection helper
Set-to-set intersection currently only has a conservative may_intersect
helper because sets can be inverted. Callers that know their sets are
not inverted must otherwise reach through two implementation layers.

Add an exact intersects overload that handles all inversion combinations
without allocating. Use it for contextual dependency collection and add
unit coverage for normal, mixed, and inverted pairs.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 15:57:10 -06:00
Behdad Esfahbod 8fe7910b00 [depend] Memoize contextual lookup recursion
Contextual GSUB dependency collection revisits completed lookup states
through each parent path. Complex Nastaliq lookup graphs therefore spend
minutes repeatedly expanding identical subgraphs.

Intern the recursion inputs and cache completed states per top-level
lookup. Remove unused contextual stack bookkeeping and avoid temporary
set allocation for exact intersection checks. Re-enable the Nastaliq
closure-parity fixtures now that they complete quickly.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 15:53:15 -06:00
Behdad Esfahbod fd7c1835ea [cff] Reject non-SEAC charstrings from their suffix (#6184)
SEAC dependency discovery interpreted every CFF1 charstring to inspect
the operand stack at endchar. Most glyphs instead end in a path operator
that has already cleared the stack, making full interpretation needless.

Recognize every Type 2 number encoding that could end immediately before
endchar and retain the full interpreter for those ambiguous cases. Also
retain it for subroutine calls, which can leave operands on the shared
stack. Reject other suffixes without interpreting the charstring.

This reduces 100 dependency scans of the SourceHan test font from 1.38s
to 0.36s and 50 full subsets from 2.56s to 2.05s. The pathological
dependency-fuzzer chunk drops from 1.31s to 0.04s. The full 270-test Meson
suite passes.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 14:59:48 -06:00
Behdad Esfahbod 0248d1aa45 Merge pull request #6181 from harfbuzz/codex/vector-raster-work-budgets
[vector/raster] Bound per-session output work
2026-08-19 14:19:46 -06:00
Behdad Esfahbod c0133a2fdd [depend] Deduplicate ligature dependency data (#6182)
Ligature dependency extraction built a set of component glyphs, but then
walked the original component array and allocated a distinct copy of the
set for every ligature record.  Repeated components and equivalent
ligature rules consequently generated millions of redundant edge lookups
and set objects on malformed fonts.

Walk the already-deduplicated component set and intern ligature sets using
the existing content-based dependency-set map.  Preserve the unused-set
reuse path by discarding only newly interned sets.

The slow dependency-fuzzer seed improves from about 0.91s and 292MB peak
RSS to 0.24s and 80MB.  The full 270-test Meson suite passes.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 14:19:32 -06:00
Behdad Esfahbod fd3fe6c54f [vector/raster] Bound output-session work
VARC's traversal budget still allowed one glyph to amplify into large
serialized paths or millions of raster edges.  Vector paint also
charged outline bytes only after a whole glyph, allowing an unbounded
single-operation overshoot.

Charge complete SVG/PDF path commands against cumulative draw and
paint context budgets, reset on clear.  Cap each raster draw session's
stored edges and stop processing outline callbacks after exhaustion.

The pathological VARC seed now keeps raster chunk 7 below 0.8 seconds
and vector chunk 7 below 1 second in the full suite.  SVG and PDF
outputs remain syntactically valid at the budget boundary.

Tested with the vector, raster, fuzzing, and full Meson test suites.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-08-19 13:39:49 -06:00
Behdad Esfahbod 3b3659d479 [raster] Fix overview examples and placement guidance
Update the draw and paint examples for the current three-argument
glyph APIs. Document that cached images must be positioned using the
raster image origins instead of reconstructed glyph bearings.

Testing: meson compile -C build harfbuzz-raster docs/harfbuzz-doc:custom

Assisted-by: Codex <codex@openai.com>
2026-08-19 13:22:54 -06:00
Garret RiegerandBehdad Esfahbod 3275f33d7a Guard against underflow in calculating val.last_arg_offset in top dict processing. (#6180)
* Guard against underflow in calculating val.last_arg_offset in top dict processing.

* [cff] Calculate last argument offset only for ROS

last_arg_offset is consumed only when serializing ROS. Calculate it
after ROS's three arguments have been successfully popped, where the
offset invariant holds, instead of guarding the calculation for every
DICT token.

Tested with: meson test -C build (270 passed)

Assisted-by: Codex <codex@openai.com>

---------

Co-authored-by: Behdad Esfahbod <behdad@behdad.org>
2026-08-19 13:11:20 -06:00
Behdad Esfahbod 46994a5f4e [raster] Reject oversized PNG decode buffers
The PNG decoder allocated its temporary RGBA buffer before the final
raster image enforced HB_RASTER_MAX_BUFFER_SIZE.  A malformed
65536-by-65536 image therefore requested and, with MALLOC_PERTURB_,
touched 16 GiB before the final image was rejected.

Apply the existing raster buffer limit before allocating the temporary
decode buffer.  Images over the limit already failed configuration, so
this only rejects them earlier.

Testing: meson test -C build

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-08-19 13:08:51 -06:00
Behdad Esfahbod 297e07229b [iter] Fix rewinding a filter at the beginning (#6179)
Detect when the underlying iterator cannot move backwards and restore the
last matching position. This avoids looping forever when the first array
items do not pass the filter.

Add a regression test that exercises the decrement which previously hung.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6178
Assisted-by: Codex <codex@openai.com>
2026-08-19 11:29:37 -06:00
Behdad Esfahbod b45e6c779e [limits] Increase graph edge count
Counterpart to https://github.com/googlefonts/fontations/pull/2059
2026-08-18 22:16:06 -06:00
Qunxin Liu ad68ba96a8 [subset] don't return early on null offset in BASE table (#6176)
As spec says these offset "may be NULL"
2026-08-18 16:59:31 -06:00
Garret Rieger b65d287b8f Add protection from multiplication overflows in hb-map.hh
- Limit max population size of map to prevent size from overflowing.
- Fix possibly overflow population * 8
- Correctly handle copying a map that's in error.
2026-08-18 15:41:54 -06:00
Garret Rieger b8c25fc5ae Fix potential multiplication overflow in cff2. 2026-08-18 15:14:53 -06:00
Garret Rieger 5a94752845 Add missing allocation failure checking in hb-subset-instancer-iup.cc. (#6175) 2026-08-18 12:01:37 -06:00
Garret Rieger 2aae9010bd Handle allocation failure during glyph_to_sid_map. 2026-08-18 10:21:58 -06:00
Behdad Esfahbod 07fe5d55a6 [directwrite] Avoid implicit double promotion
The RTL-safe offset is intentionally double precision, while the font
scale is a float. Cast the scale explicitly before multiplying so GCC's
-Wdouble-promotion does not warn about the intended conversion.

Testing: MinGW DirectWrite build with -Wdouble-promotion
Testing: meson test -C build --print-errorlogs

Assisted-by: Codex <codex@openai.com>
2026-08-18 04:28:08 -06:00
Garret Rieger 817b958f22 Add a max recursion depth guard to reverse_cursive_minor_offset() 2026-08-17 19:09:56 -06:00
Garret Rieger 402500e925 Clamp conversion from float back to int. 2026-08-17 19:09:43 -06:00
Garret Rieger 6c2107ace7 Fix arithmetic overflows in IUP handling.
Fixes https://oss-fuzz.com/testcase-detail/4688270404157440.
2026-08-17 19:09:43 -06:00
Behdad Esfahbod d54151cf08 Merge pull request #6169 from harfbuzz/raster-flatten-clip
[raster] Clip and budget Bézier flattening
2026-08-17 17:10:07 -06:00
Behdad Esfahbod c91e0cace0 Merge pull request #6162 from harfbuzz/fix-directwrite-libstdcxx
[directwrite] Avoid C++ allocation runtime
2026-08-17 15:13:59 -06:00
Behdad Esfahbod e8f5044684 [raster] Trim ordinary-case cost of the flattening guards
Three refinements to the clip/budget checks the two previous commits
added to the Bézier flatteners, so well-behaved fonts pay almost
nothing for them:

- Subdivided control points are convex combinations of their
  parent's, so once a node's bounding box is entirely inside the
  clip box no descendant can leave it.  Track that per node and skip
  the bounding-box test for such subtrees; a typical fully-visible
  curve now tests once at the root instead of at every node.  Only
  curves straddling the box boundary keep testing, and those are the
  ones where the test prunes real work.

- Resolve the effective clip box (internal clip box, else fixed
  extents; expanded by one pixel) once when it changes, cached in
  hb_raster_draw_t, instead of re-deriving it on every curve.

- Keep the work-budget counter in a local and write it back once per
  flattener call rather than decrementing through a pointer per
  subdivision.

Measured with hb-raster-all (all glyphs, pinned CPU, perf stat -r 10)
against the pre-guard baseline: cubic-heavy SourceSansPro at 1024px
is back to baseline parity (was +0.8% with the naive per-node check);
quad-heavy Amiri at 256px goes from +3.2% to ~+2.6% (residual is the
per-curve root test and budget setup on very short curves; the
workload is a flattening-heavy microbenchmark).

All-glyph renders of Bungee, Bitcount (COLR), Amiri, and AktivGrotesk
VF stay byte-identical; the timeout seed stays at 0.05s; full test
suite passes.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 14:57:38 -06:00