* [test/fuzzing] Skip hb-depend-closure-parity without GLib
It depends on GLib unlike the other fuzzers.
* [ci] Build the msan bot without external dependencies
We don’t care about msan errors in code that is not ours, and some
libraries like GLib are not built with memory sanitizers in mind.
* [ci] Don't pipe sanitizer test output
The pipe was masking meson exit status, and it was redundant anyway
since the sanitizer output is is already symbolized and demangled.
* [COLR] Fix integer overflow in get_extents
Use to_glyph_extents(), which guards against this.
Update test expectation since we now round instead of truncate.
The subset umbrella header already carries the public subset API, but it
missed hb-subset-serialize.h even though the serialize symbols are part
of the subset section. Include the serialize header from hb-subset.h so
users can get the API through the top-level subset header.
Keep hb-subset-serialize.h directly includable for compatibility, but
emit a diagnostic asking users to include hb-subset.h instead. Update the
local repacker tests to use the umbrella header and verify the API is
available there.
Testing: meson compile -C build test/api/test-subset-repacker test/fuzzing/hb-repacker-fuzzer
Testing: meson test -C build --suite api
Testing: meson test -C build
Assisted-by: OpenAI Codex
The depend closure parity Meson test ran 1024 random cases per font over
large chunks. That made a single test spend excessive time repeatedly
walking huge cmap data, and the Noto Nastaliq fonts currently spend tens
of seconds or more in contextual GSUB dependency graph construction
before parity comparisons even start.
Cache the unicode-to-glyph map per font, select codepoints with one
linear pass over the cmap, and avoid glyph-starting non-GSUB tests for
huge-cmap fonts. Limit the Meson parity workload to a smaller fixed
sample and skip the two known Nastaliq graph-construction outliers until
that algorithmic path is made fast enough for the default test suite.
Testing: meson test -C build depend-fuzzer-chunk-7 depend-closure-parity-chunk-0
Testing: meson test -C build --suite api
Testing: meson test -C build
Assisted-by: OpenAI Codex
hb_pdf_build_indexed_smask() computed its buffer sizes with unchecked
32-bit arithmetic:
unsigned raw_len = (width + 1) * height;
...
out->resize (width * height);
width/height come straight from the attacker-controlled PNG IHDR (the
vector-PDF path re-parses IHDR itself and does not clamp dimensions,
unlike sbix). For width = height = 65536, (width + 1) * height wraps to
65536 and width * height wraps to 0. A crafted IDAT inflating to the
wrapped raw_len passes the length check, the mask buffer is resized to
zero, and the per-pixel loop then writes through out->arrayZ[y*width+x]
and reads past raw -- an out-of-bounds write / NULL-page store and crash.
Reject zero/degenerate dimensions and use hb_unsigned_mul_overflows()
for both (width + 1) * height and width * height before allocating,
sizing the inflate, and indexing. This bounds every subsequent
raw + y*(width+1) and out->arrayZ[y*width+x] access.
Add a CBDT regression seed embedding a 65536x65536 indexed PNG with a
tRNS chunk; it reaches the soft-mask builder through
hb_font_paint_glyph -> CBDT::paint_glyph -> hb_pdf_paint_image and
crashed pre-fix under ASAN/UBSan at hb-vector-paint-pdf.cc:617.
Fixes: GHSA-gmjm-qc3c-qfp8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The PNG chunk-bounds check in hb_pdf_paint_image() used wrapping
32-bit unsigned arithmetic:
if (pos + 12 + chunk_len > len)
break;
A large attacker-controlled chunk_len (e.g. 0xFFFFFF30) wraps
pos + 12 + chunk_len below len, so a truncated PLTE chunk passes the
check. The oversized plte_len is then trusted during palette
serialization in add_xobject_png_image(), reading far past the input
buffer -- an out-of-bounds read and deterministic crash.
Rewrite the bounds checks to be non-wrapping, relying on the invariant
pos <= len (len >= 8 is checked earlier): gate the loop on
len - pos >= 12 and reject a chunk with chunk_len > len - pos - 12.
This keeps pos <= len across pos += 12 + chunk_len and makes every
in-loop read (chunk header and chunk payload) provably in bounds.
Add a regression seed font that embeds a malformed indexed PNG with an
oversized PLTE length via sbix. It reaches the vector-PDF paint path
through hb_font_paint_glyph -> sbix::paint_glyph -> hb_pdf_paint_image
and crashed pre-fix under ASAN at hb-vector-paint-pdf.cc:222; it now
renders cleanly.
Fixes: GHSA-9m78-3jcg-57f2
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Clip mask extents can have extreme signed origins after malformed
or heavily transformed outlines. Subtracting the surface origin in
int overflowed for cases such as 0 - INT_MIN.
Keep the mask-to-surface coordinate conversion in int64_t until
after intersecting with the finite clip and surface bounds, then
convert to unsigned only for proven in-range pixels.
Add the minimized OSS-Fuzz seed to the raster fuzzer corpus.
Testing: meson test -C build
Fixes: https://oss-fuzz.com/testcase-detail/4621471331450880
Assisted-by: OpenAI Codex <codex@openai.com>
hb_font_get_nominal_glyph can return GIDs >= num_glyphs for
malformed cmap format 4 tables. The subsetter's plan creation
filters these via _remove_invalid_gids, but the parity checker's
codepoint-to-glyph mapping did not. This caused spurious
over-approximation on AOTS cmap4 test fonts.
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
When the parity checker finds unexpected over-approximation (depend
closure has extra glyphs without flagged edges), check whether the
font has self-feeding GSUB lookups — lookups whose output coverage
overlaps their input coverage. These create transitive chains that
the depend closure follows to completion while the subsetter's
iteration-capped closure truncates.
No shaper re-applies a lookup to its own output within a single
feature application, so the extra glyphs are harmless. The
detection traces extra glyphs through self-feeding feature edges
from the subset closure; if all are explained, the test passes.
Detection runs only on the failure path and is O(edges), so
well-formed fonts (which don't have self-feeding lookups) pay no
cost.
Also document MATH single-pass closure and GSUB self-feeding chains
in depend-for-closure.md and depend-implementation.md.
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Split the former "test generation infrastructure" section into three
labelled subsections:
- Random sampling utilities (rng_range / rng_select_distinct / rng_select_from_set)
- Font and input queries (get_gsub_features / parse_unicodes / parse_gids / parse_features)
- Test parameter generation (test_params / generate_test_from_explicit / generate_test_from_seed)
get_gsub_features was previously stranded between the RNG helpers and the
parsers; the new header makes clear it belongs with the input queries.
No logic changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reorder the file so a reader encounters code in the order they need to
understand it:
1. Overview comment explaining the two-closure comparison approach
2. Configuration globals and init_parity_config()
3. Closure algorithm (depend side): deferred_ligature_t, depend_closure_ctx_t,
check_context_satisfied, process_edges_for_tables, compute_depend_closure
4. Closure algorithm (subset side): compute_subset_closure
5. Comparison and reporting: print_test_params, compare_closures
6. Test generation infrastructure: rng helpers, get_gsub_features,
parse_unicodes/gids/features, test_params, generate_test_from_*
7. LLVMFuzzerTestOneInput
Previously the test generation infrastructure (hundreds of lines of seed and
parser code) appeared before the parity checking logic, forcing a reader to
hold a lot of context before seeing what the file was for. The forward
declaration of get_gsub_features() is also removed since it now precedes
parse_features(). No logic changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add `rng_prob_hit()` helper to replace three repeated injection-check
patterns, each of which was 4–6 lines of std::uniform_real_distribution
boilerplate.
- Add `depend_closure_ctx_t` struct to group the parameters that were
threaded individually through `process_edges_for_tables` (10 params)
and `compute_depend_closure` (9 params); both now take 2–3 params.
- Remove dead `vs_to_gid` map that was created, passed through three
call layers, and never read.
- Fix GSUB-stage indentation in `compute_depend_closure`: the old code
had a spurious outer `{ }` block containing all five table stages,
with the `if (!skip_gsub)` body indented at the wrong level.
- Move `ligature_set_glyphs` into the GSUB stage block where it belongs.
No behaviour change; all tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ContextDependLookupContext / ChainContextDependLookupContext: replace
duplicate struct definitions with typedefs of their Closure counterparts,
removing the now-unnecessary reinterpret_casts and layout-identity comments
- test/fuzzing/meson.build: switch depend-closure-parity from api_fonts_glob
to subset_fonts_glob; remove api_fonts_glob (the fuzzer produces malformed
fonts anyway, per behdad review)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Follows HarfBuzz convention: return total count, take start_offset +
entry_count IN/OUT + entries array. This allows callers to query the
total without filling, page through entries, or fetch all at once.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename all public symbols hb_depend_* → hb_subset_depend_*
- Rename hb_depend_t → hb_subset_depend_t
- Replace get_glyph_entry (multi out-param) with lookup_glyph (fills
hb_subset_depend_entry_t struct; fields use ligature_set_index /
context_set_index)
- Rename get_set_from_index → lookup_set
- Remove hb_depend_print from public API (util/hb-subset-depend TODO)
- Move hb_subset_depend_edge_flags_t to hb-depend.h; apply
HB_MARK_AS_FLAG_T in hb-depend-data.hh (internal header only, since
hb-algs.hh is not available in public headers)
- Rename HB_DEPEND_EDGE_FLAG_* → HB_SUBSET_DEPEND_EDGE_FLAG_*
- Update gen-def.py, check-symbols.py, and all test callers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace HB_DEPEND_API with HB_NO_SUBSET_DEPEND gated on HB_EXPERIMENTAL_API
and HB_LEAN in hb-config.hh, with HB_SUBSET_DEPEND_API opt-in to allow
enabling without full experimental API. Remove depend_api meson option;
depend tests now build under experimental_api=true. Fold depend symbols into
experimental symbols in gen-def.py.
Internal fixes: use free_set_list.pop(), push_or_fail() for allocation safety,
return const hb_set_t* from internal get_set_from_index. Ligature.hh: use
hb_sink iterator, rename ligset→ligset_idx, source→gid. Remove stale
test_depend_cmap unit test (cmap extraction was removed in d4d4c635).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace bare assert(blob) with a proper error message when
hb_blob_create_from_file_or_fail returns NULL. This gives users
a clear indication of which file couldn't be loaded instead of
a cryptic assertion failure.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
UVS (Unicode Variation Sequence) edges in the depend graph couldn't
properly represent the filtering requirement that BOTH the base unicode
AND variation selector must be in the input unicodes. This caused
over-approximation in depend closure vs subset closure.
Solution: Handle UVS separately using existing query APIs
- Skip all cmap edges during depend closure processing
- Use hb_font_get_variation_glyph() to query UVS mappings directly
- For GSUB tests: Use input codepoints directly for UVS queries
- For non-GSUB tests: Build unicodes from starting glyphs via forward
cmap iteration (hb_face_collect_nominal_glyph_mapping)
This correctly matches subset's UVS handling while keeping the depend
graph focused on non-UVS dependencies.
Also fixes -t parameter to support full 64-bit test seeds by parsing
as string before converting to uint64_t.
Test results:
- NotoSansMath-Regular.ttf: 100,000 tests pass
- Padauk-Bold.ttf: 100,000 tests pass
- ReemKufiInk-Regular.ttf: 100,000 tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The depend fuzzers (hb-depend-fuzzer and hb-depend-closure-parity)
use the depend API which is only available when the depend_api build
option is enabled. However, the fuzzing meson.build was unconditionally
building these fuzzers for all configurations, causing CI build failures
when depend_api was disabled (the default).
This change:
- Splits the fuzzers list into regular tests and depend_tests
- Only builds depend-related fuzzers when HB_DEPEND_API is defined
- Maintains existing behavior for all other fuzzers
- Keeps the test execution conditional as before (lines 142-166)
This fixes all CI build failures across Linux, macOS, Windows (MSVC/MinGW),
and sanitizer builds.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Update hb-depend-fuzzer to fully exercise the depend API by actually
retrieving and validating sets, not just accessing edge values.
Changes:
- Retrieve ligature sets when present using hb_depend_get_set_from_index
- Retrieve context sets when present using hb_depend_get_set_from_index
- Handle nested context sets (indirect references with 0x80000000 bit)
- Check all sets for sanity using hb_set_get_population
- Warn if empty sets are encountered (which shouldn't happen)
This catches bugs in set storage, retrieval, and the encoding of nested
context set references.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace manual command-line parsing with glib's GOptionContext/GOptionEntry
system to match other HarfBuzz test tools.
Changes:
- Add glib_dep to meson.build for hb-depend-closure-parity
- Use G_OPTION_ARG_INT64 for hex test seeds (requires 0x prefix)
- Implement parse_inject_rate callback for optional float args with defaults
- Update help text to require 0x prefix for hex values
- Call print_usage() on argument validation errors
- All test seed output verified to use 0x prefix
Benefits:
- Automatic --help generation by glib
- Consistent with other HarfBuzz utilities
- Simpler error handling and validation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit addresses multiple code review comments:
1. Switch RNG to std::mt19937 for deterministic tests
- Replace std::rand/srand with std::mt19937 in parity checker
- Use std::uniform_int_distribution for all random number generation
- Ensures test determinism across platforms for non-error-injection tests
2. Convert debug fprintf to DEBUG_MSG_LEVEL
- Convert GSUB lookup processing prints to DEBUG_MSG_LEVEL(DEPEND, nullptr, 1, 0, ...)
- Visible at HB_DEBUG_DEPEND=2 or higher for detailed per-lookup debugging
3. Rename function for consistency
- hb_depend_from_face → hb_depend_from_face_or_fail
- Follows HarfBuzz convention for functions returning nullptr on failure
- Update all call sites, documentation, and code comments
4. Adopt established set deduplication pattern
- Change from hb_vector_t<hb_set_t> to hb_vector_t<hb::unique_ptr<hb_set_t>>
- Use pointer-based hashmap: hb_hashmap_t<const hb_set_t*, hb_codepoint_t>
- Leverages hb_hash's content-based deduplication via pointer dereferencing
- Follows pattern established elsewhere in HarfBuzz codebase
5. Separate ligature and context set semantics
- Rename free_set → free_ligature_set (no hashmap manipulation)
- Rename new_set → new_ligature_set (no hashmap manipulation)
- Rename find_or_create_set → find_or_create_context_set (only function using hashmap)
- Makes it explicit which sets are deduplicated (context) vs unique (ligature)
- Update all call sites in Ligature.hh, ReverseChainSingleSubstFormat1.hh, hb-ot-layout-gsubgpos.hh
6. Code cleanup
- Remove unused add_to_ligature_set function (dead code)
- Refactor new_ligature_set(cp) to delegate to new_ligature_set(set)
- Move set_to_index declaration near sets/free_set_list for better organization
All tests pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Two related fixes:
1. Context set under-approximation fix (hb-ot-layout-gsubgpos.hh):
When a direct requirement (from input positions) overlapped with a
disjunctive set (backtrack/lookahead), the code incorrectly added
the filtered (remaining) set as an additional requirement. Fix:
if position_context intersects with original_set at all, the
disjunctive requirement is already satisfied - don't add anything.
2. Parity checker ligature fix (hb-depend-closure-parity.cc):
When processing deferred ligatures, store {dependent, ligature_set,
flags} at deferral time instead of re-scanning edges later. This
preserves the feature filtering that was already done and correctly
propagates edge flags.
Also updates edge flag documentation to correctly explain the mechanism:
- Depend extraction records edges based on static input coverage/class
- During closure, lookups within a rule are applied sequentially
- Lookups at earlier positions may transform later positions
- Multiple lookups at same position may interact (one produces a glyph,
another immediately consumes it as an "intermediate")
- So a glyph matching coverage might not persist when closure traverses
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Two bugs were fixed in the closure parity checker:
1. Feature filtering for ligatures: When processing deferred ligatures,
the code re-scanned all edges to find satisfying ligature sets but
forgot to filter by active features. This allowed ligatures to be
added via edges from inactive features if their ligature set happened
to be satisfied.
2. Flag checking for ligatures: When adding ligatures, we weren't
checking or propagating the edge flags (FROM_CONTEXT_POSITION,
FROM_NESTED_CONTEXT), so flagged ligature edges weren't being
reported as expected over-approximation.
Also includes related changes to the depend extraction:
- Add FROM_NESTED_CONTEXT flag for nested contextual lookups
- Add context handling for ReverseChainSingleSubstFormat1
- Remove cmap from glyf/CFF closure stage (UVS edges shouldn't be
followed for glyph-based closure)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added missing documentation for the hit_flagged_edge output parameter
in process_edges_for_tables() and compute_depend_closure() function
comments. This parameter tracks whether edges marked with
FROM_CONTEXT_POSITION flag are traversed during closure computation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Edges created from non-zero positions in multi-position contextual rules
can consume intermediate glyphs (glyphs produced then immediately consumed,
never settling in closure). This causes depend's closure to include extra
glyphs compared to subset's closure, which is expected behavior.
Added HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION flag to mark these edges
at extraction time. Updated parity checker to track when such edges are
hit during closure computation and distinguish between:
- Expected over-approximation (hit flagged edge): informational only
- Unexpected over-approximation (no flagged edge): critical error
This enables detection of genuine bugs (unexpected over-approximation)
while allowing expected cases from intermediate glyphs.
Updated all API callers and documentation to include nullable flags
parameter. Renamed parity checker terminology from "fuzzer" to "parity"
for clarity.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Documentation updates:
- Add comprehensive context_set documentation to depend-api.md with
encoding details and example code for check_context_satisfied()
- Update depend-for-closure.md: remove obsolete over-approximation
analysis, reflect that recent testing shows no over-approximation
with proper context_set filtering
- Update depend-implementation.md: correct descriptions of active
glyph filtering, sequential accumulation, ligature sets, and
context recording to match current implementation
- Fix terminology: change 'binning' to 'segmentation' throughout
- Fix hb-depend-data.hh:557: use HB_CODEPOINT_INVALID instead of 0
for layout_tag default value
Fuzzer enhancements (hb-depend-closure-parity):
- Add explicit test mode with command-line options similar to
hb-subset conventions:
--unicodes=LIST Unicode codepoints (U+XXXX, decimal, ranges)
--gids=LIST Glyph IDs (decimal, ranges)
--no-layout-closure Skip GSUB closure
--layout-features=LIST GSUB features (comma-separated or *)
- Support multiple input formats:
--unicodes=U+0041,U+0042,U+0043
--unicodes=65-90
--gids=10-50 --no-layout-closure
--layout-features=liga,calt or --layout-features='*'
- Add robust input parsing with validation to prevent infinite loops
on invalid input (e.g., --gids=abc or --unicodes=U+GGGG)
- Add error checking for conflicting options
This allows reproducing random test cases manually and testing
specific scenarios without finding the right seed.
Tested: All modes produce identical results to seed-based tests.
Renames:
- hb-depend-fuzzer.cc → hb-depend-closure-parity.cc
- hb-depend-fuzzer-main.cc → hb-depend-closure-parity-main.cc
- hb-depend-security-fuzzer.cc → hb-depend-fuzzer.cc
The closure parity test validates correctness by comparing the depend
API implementation against the battle-tested subset closure calculation,
ensuring the two implementations stay synchronized. It runs on valid
fonts from test/api/fonts/.
The depend fuzzer is a security fuzzer that tests robustness against
malformed input, following the standard HarfBuzz fuzzer pattern. It runs
on malformed fonts from test/fuzzing/fonts/.
Updated test/fuzzing/README.md to document both tools and their distinct
purposes. Updated meson.build to reflect the new naming in test
registration.
This commit implements the experimental depend API for extracting glyph
dependency graphs from OpenType fonts. The depend API provides the foundation
for computing glyph closures and analyzing font structure.
The implementation significantly improves upon the initial draft (commit
3f59433d5) by adding contextual filtering to reduce over-approximation while
still capturing complete dependency graphs.
Core Architecture
-----------------
The depend implementation operates in graph extraction mode: it walks all font
tables once to build a complete dependency graph. The key innovation is
contextual filtering that reduces over-approximation compared to the naive
approach.
Contextual Filtering for Reduced Over-Approximation
----------------------------------------------------
The initial implementation (3f59433d5) recorded dependencies for ALL glyphs in
every lookup's coverage, leading to significant over-approximation. The current
implementation filters dependencies based on context:
**Individual Lookups**: Each lookup's depend() method filters by active glyphs:
// Old approach (3f59433d5)
+ hb_iter (this+coverage) // ALL coverage glyphs
| hb_apply (record_dependency)
// New approach
hb_set_t intersection;
(this+coverage).intersect_set (c->parent_active_glyphs(), intersection);
+ hb_iter (intersection) // ONLY contextually relevant glyphs
| hb_apply (record_dependency)
**Contextual Lookups**: ContextFormat1/2/3 and ChainContextFormat1/2/3 set up
active glyph contexts for nested lookups:
hb_set_t* cur_active_glyphs = c->push_cur_active_glyphs();
get_coverage().intersect_set(*c->glyphs, *cur_active_glyphs);
// Process rules with filtered coverage
+ hb_zip (this+coverage, ruleSet)
| hb_filter ([&] (hb_codepoint_t g) {
return c->parent_active_glyphs().has(g);
}, hb_first)
| hb_apply (process_rule)
This significantly reduces over-approximation for simple cases while maintaining
complete graph coverage.
**Intentional Over-Approximation at Nested Boundaries**: When contextual rules
invoke nested lookups, we pass ALL glyphs to ensure no edges are missed:
// In context_depend_recurse_lookups()
cur_active_glyphs->set (*c->glyphs); // Universe for nested lookups
This design choice prioritizes completeness over precision at contextual
boundaries, which is appropriate for graph extraction.
Edge Deduplication and Performance
-----------------------------------
Dependency extraction can generate millions of potential edges. To maintain
acceptable performance:
- Edge hashing (compute_edge_hash): O(1) duplicate detection via hash table
keyed on (source, table_tag, layout_tag, dependent, ligature_set_contents)
- Hash collision handling: Falls back to O(n) linear search through glyph's
existing dependencies only on collision (rare)
- Component vectors: Stores edge components for collision detection
- Post-extraction cleanup: Frees temporary structures (edge_hashes,
lookup_features) to reduce memory footprint
Table-Specific Extraction
--------------------------
- **cmap**: Unicode → glyph mappings including UVS (Unicode Variation Sequences)
- **GSUB**: All substitution rules with feature tags and ligature set tracking
- Handles all 8 GSUB lookup types including Extension (type 7)
- Records which features reference each dependency
- Groups ligature alternatives via ligature_set indices
- **glyf**: TrueType composite glyph components
- **CFF**: CFF1 SEAC (Standard Encoding Accented Character) composites
- **COLR**: Color layer dependencies for both COLRv0 and COLRv1
- Filters self-referential PaintGlyph to prevent trivial cycles
- **MATH**: Mathematical variant glyphs and assembly components
CFF SEAC dependencies use table_tag='CFF ' with layout_tag=0 and
ligature_set=HB_CODEPOINT_INVALID, matching the pattern used for glyf.
Data Structure: hb_depend_data_record_t
----------------------------------------
Each dependency edge contains:
- table_tag: Source table (GSUB, glyf, CFF, COLR, MATH, cmap)
- dependent: Target glyph ID
- layout_tag: Feature tag (for GSUB) or UVS codepoint (for cmap), else 0
- ligature_set: Index into sets array for ligature alternatives, else INVALID
- context_set: Reserved for future contextual filtering (currently unused)
Graph stored as vector indexed by glyph ID, each containing vector of records.
Testing and Documentation
--------------------------
- test/api/test-ot-depend.c: Comprehensive test suite (645 lines)
- Tests all table types and GSUB substitution formats
- Includes regression tests for edge cases
- Uses ContextFormat2-Depend-Test.ttf (minimized from 486KB to 85KB)
- test/fuzzing/hb-depend-fuzzer.cc: Production-quality closure implementation
- Demonstrates correct ligature set handling
- Includes feature filtering and over-approximation analysis
- Reference implementation for depend-based closure computation
- docs/depend-api.md: Public API documentation with usage examples
- docs/depend-for-closure.md: Guide to using depend for closure computation
- docs/depend-implementation.md: Implementation details and architecture
Build System
-------------
- Meson option: -Ddepend_api=true
- Compile flag: -DHB_DEPEND_API
- Symbols in libharfbuzz-subset.dylib (applications must link both
libharfbuzz and libharfbuzz-subset)
Status: Experimental API, subject to change.
These are convenience APIs, not typesetting APIs — positioning
is the caller's responsibility via set_transform(). This
matches the GPU API which never had pen parameters.
All callers updated to use set_transform with pen position
before each _glyph call.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Malicious fonts with extreme scale values cause huge pixel
buffer allocations across multiple push_group surfaces. The
library correctly bounds individual surfaces at 1 GB, but
stacked group surfaces can exceed the fuzzer RSS limit.
Cap the font scale to 1000 in the harness so the exercised
surface stays within fuzzer memory constraints.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When clip nesting exceeds HB_GPU_PAINT_MAX_CLIP_DEPTH (3),
push_clip_glyph sets unsupported=true but still increments
clip_depth. emit_all_clip_sub_blobs then iterated clip_depth
without capping, reading past the fixed-size clip_stack array.
Cap the iteration at HB_GPU_PAINT_MAX_CLIP_DEPTH.
Fixes: https://oss-fuzz.com/testcase-detail/6573156621156352
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Flat mode disabled glyph reuse / caching to produce inline-
everything SVG output. Its main use case was making
hb-vector SVGs safe to concatenate side-by-side in a single
document, but the recently-added svg_set_prefix API solves
that without giving up the cache. No remaining callers in
tree (util/vector-output.hh's --flat option goes too).
Removes:
- hb_vector_draw_set_flat / get_flat
- hb_vector_paint_set_flat / get_flat
- the `flat` field on both contexts
- all `if (flat)` / `bool can_cache = !flat` branches
- the --flat option in util/vector-output.hh
- the four "flat*" expected files in test/vector/basic
- the flat_draw / flat_paint params in the vector fuzzer
- sections-list entries
meson test --no-rebuild green (241/241).
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three accumulator vectors -- ops, sub_blobs, transform_stack --
can enter error state via failed push_or_fail() under
failing-malloc. Once in error state, resize(0) short-circuits
at the in_error() guard in alloc() and leaves length unchanged.
In hb_gpu_paint_clear that means the next iteration's clear
walks the stale entries again. For sub_blobs this is a
double-destroy: the blob pointers were already freed in the
previous clear, and hb_blob_destroy reads the dead ref_count
field -- heap-use-after-free.
Fix by calling vector.reset(), which clears the error state
before resizing to 0. Matches the pattern hb_gpu_draw_clear
already uses for draw->curves.
Found by oss-fuzz/CIFuzz on hb-gpu-fuzzer; minimized testcase
added to the fuzz corpus.
Assisted-by: Claude <noreply@anthropic.com>
Two sites queried color-stop count, resized the scratch vector to
match, then called hb_color_line_get_color_stops() passing the
requested count as the write capacity. If the resize() failed
(OOM), the vector stayed at its previous (smaller) length while
the callee still wrote the full requested count -- heap-buffer-
overflow.
Fixed by checking resize() and bailing: build_gradient_function
returns 0, paint_sweep_gradient returns. Matches the pattern
already used in hb-raster-paint.cc and hb-vector-paint.cc.
Found by oss-fuzz/CIFuzz on hb-vector-fuzzer against a sweep-
gradient COLRv1 glyph under failing-malloc.
Assisted-by: Claude <noreply@anthropic.com>
The existing hb-gpu-fuzzer only exercised hb_gpu_draw. Add a
parallel paint round-trip per glyph (paint_glyph -> encode ->
recycle_blob) so the paint encoder gets the same fuzzed-input
coverage -- gradient / transform / composite parsing in
particular has a lot more surface than the slug encoder.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_raster_paint_glyph() took the palette index and foreground
color as per-call arguments, duplicating state that also lives on
the paint context (foreground via hb_raster_paint_set_foreground,
palette previously only available as a per-call arg). This gave
callers two paths for configuring the same state.
Drop the per-call palette/foreground arguments and require callers
to configure them via setters before painting, matching the
already-established pattern in hb_vector_paint_glyph() and
elsewhere in the subsystem.
- Drop palette and foreground args from hb_raster_paint_glyph().
- Add hb_raster_paint_set_palette() / _get_palette() and a
hb_raster_paint_get_foreground() companion.
- Store palette on hb_raster_paint_t (default 0).
- Update util/raster-output.hh, util/hb-raster-all.cc, and
test/fuzzing/hb-raster-fuzzer.cc to the new API.
- Update the hb-raster section-doc example.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously only HB_VECTOR_FORMAT_SVG was fuzzed. Factor the
create/paint/render body into a helper and call it twice per
input — once for SVG, once for PDF — so the PDF-specific code
paths get the same coverage:
- PDF content-stream encoder
- Type 2/3 shading + stitching function builder
- Type 6 Coons-patch sweep gradient encoder (hb_pdf_add_sweep_patch)
- PNG IDAT passthrough
- Indexed-PNG SMask builder (hb_pdf_build_indexed_smask, zlib inflate
+ PNG un-filter + palette-to-alpha mapping)
Input-fuzzed knobs (precision, flat-draw, flat-paint) are shared
between the two formats.
Smoke-tested on a handful of existing fuzzing/fonts corpus entries;
all pass clean.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bring hb_gpu_draw_encode into line with the rest of the render APIs:
auto-clear on success, and return the computed glyph extents to the
caller via a new out-parameter (nullable).
HB_EXTERN hb_blob_t *
hb_gpu_draw_encode (hb_gpu_draw_t *draw,
hb_glyph_extents_t *extents);
Consumers typically need both the encoded blob and the glyph's
extents to size the quad they'll draw into in the vertex shader;
returning them together removes a redundant trip through the draw
state and lets encode() auto-clear like hb_vector_*_render() and
hb_raster_*_render() do.
Drop hb_gpu_draw_get_extents() from the public API — its only
role was reading extents out of the draw state post-encode, which
the new encode() signature makes redundant. The computation
stays (moved to a static _hb_gpu_draw_get_extents helper) so
encode() can call it before auto-clear wipes the state.
ABI break for anyone who had already wired up against the 14.0.0
hb_gpu_draw_encode signature or hb_gpu_draw_get_extents, but the
library is new/experimental and the two in-tree consumers
(test/api/test-gpu.cc, util/gpu/demo-font.cc, util/hb-gpu-encode-all.cc,
test/fuzzing/hb-gpu-fuzzer.cc) are updated here.
All 240 tests pass.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Drop "svg" from the names since flat/precision settings apply
equally to PDF output. The new names follow the hb_vector_draw_*
/ hb_vector_paint_* convention:
hb_vector_svg_set_flat -> hb_vector_draw_set_flat
hb_vector_svg_set_precision -> hb_vector_draw_set_precision
hb_vector_svg_paint_set_flat -> hb_vector_paint_set_flat
hb_vector_svg_paint_set_precision -> hb_vector_paint_set_precision
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_extents_t::to_glyph_extents() rounded bounds to hb_position_t
before subtracting them. Extreme extents from fuzzed VARC and
raster paths could therefore overflow signed int arithmetic while
forming glyph widths or heights.
Compute the rounded endpoints in double, clamp the exported values
to hb_position_t, and reject non-finite results. Also avoid the
same overflow in the reverse hb_glyph_extents_t constructor, add
an internal regression for the shared helper, and include the
minimized raster testcase.
Fixes: https://oss-fuzz.com/testcase-detail/4826864710647808
Not-tested: Skipped by request.
Assisted-by: OpenAI Codex
hb_gpu_draw_get_extents() cast rounded bounds to hb_position_t
before subtracting them. A fuzzed glyph outline with an extreme
negative bound could therefore overflow signed int arithmetic while
forming width or height.
Compute the rounded bounds in double, reject non-finite values, and
clamp the exported extents to hb_position_t before returning them.
Add an API regression that covers the OSS-Fuzz testcase through the
public GPU draw API.
Fixes: https://oss-fuzz.com/testcase-detail/5918954634936320
Tested: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
Malformed reflected gradients can produce very large finite
gradient parameters. The raster backend normalized reflect
mode by casting floorf(t) to int, which can overflow and
drive LUT lookups past the fixed-size stack buffer.
Fold reflected coordinates with fmodf(), clamp LUT inputs
defensively, and add the minimized oss-fuzz raster
testcase to the corpus.
Fixes: https://oss-fuzz.com/testcase-detail/6597066439852032
Tested: meson test -C build
Co-Authored-By: OpenAI Codex <codex@openai.com>