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>
Instead of just checking that the ligature set is non-empty, now verify
it contains the expected component glyphs (1823 and 1829) that form the
ligature 1910 (uni03020300).
This matches the validation pattern used in the NotoSans-Bold test and
provides proper regression testing.
Enhance test_depend_gsub_formats to fully exercise the ligature set API
for SourceSansPro-Regular.otf, not just check that a set index is returned.
Changes:
- Create temporary set to retrieve ligature set contents
- Call hb_depend_get_set_from_index to retrieve the set
- Verify the set is non-empty (contains component glyphs)
- Log the number of components found
- Destroy temporary set
This matches the validation pattern used in the NotoSans-Bold test and
ensures the full depend API is exercised consistently across all
ligature tests.
🤖 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.
get_base_glyph_paintrecord() looked up the BaseGlyphList with the
reference-returning bsearch(), which yields the all-zero Null object
when the glyph is absent, and then rejected non-matches by comparing
record->glyphId against the requested gid. For glyph 0 the Null
object's glyphId (0) equals the requested gid, so the sentinel was
taken for a real record. .notdef then resolved to a bogus empty paint,
and COLR::get_extents() returned success with 0,0,0,0 instead of
letting hb_ot_get_glyph_extents() fall back to the glyf outline.
Use bfind(), which reports presence directly, so a missing glyph
(including glyph 0) returns nullptr and extents fall back correctly.
This surfaced as a mark-positioning difference: fallback mark
positioning centers a mark using the base and mark glyph extents, so a
.notdef mark over a space was positioned differently from shapers that
report the real outline extents (e.g. fontations/HarfRust).
Testing:
- test/api/test-extents.c: glyph 0 (.notdef, has an outline) now
reports its outline extents; updated the expectation accordingly.
- b/util/hb-shape Noto-COLRv1.ttf -u 0020,0650 now matches
--font-funcs=fontations.
- meson test -C build (246 passed, 1 skipped)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wire the HarfRust shaper through the active hb_font_t callback
surface so custom hb_font_funcs_t are respected during shaping.
Add a harfrust-specific test-shape invocation to cover that path.
Tested: meson test -C build test-shape-harfrust
Tested: HB_SHAPER_LIST=harfrust meson test -C build harfbuzz:shape_threads
Tested: HB_SHAPER_LIST=harfrust meson test -C build test-shape
Assisted-by: OpenAI Codex
---------
Co-authored-by: Chad Brokaw <cbrokaw@gmail.com>
Round COLRv1 alpha values when packing them into 8-bit colors in the
native OpenType and FreeType paint paths.
This removes the old downward truncation bias and aligns native output
with the backend behavior expected by the updated paint fixtures.
Update the affected test-paint fixtures for the rounded alpha values.
Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
Reduce linear gradient anchors and normalize color lines before
printing them in test-paint. This makes the transcript reflect the
renderer-facing gradient geometry instead of backend-specific raw
COLRv1 anchors and stop ranges.
Also normalize signed zero in transform output so the fixtures stay
stable across backends.
Testing:
CCACHE_DISABLE=1 meson test -C build test-paint --print-errorlogs
Assisted-by: OpenAI Codex
Make the native COLRv1 paint paths report the root clip in font
units under the font transform. This matches the order used by
fontations and removes the need to pre-scale the HB-OT clip extents.
For the FreeType path, add a helper to convert FT_ClipBox values
back to font units before pushing them under the font transform, and
share that conversion with nested COLR glyph clip boxes.
Update paint and vector expectations for the new transform/clip stack.
Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
The disabled assertions cover behavior from an older beyond-64k proposal.
That proposal has since changed, and current backends should not be
required to implement the stale loca-derived glyph count and metrics rules.
Keep the checks visible as disabled reminders until the library code is
adapted to the updated design.
Tested with:
CCACHE_DISABLE=1 HB_FONT_FUNCS=fontations meson test -C build test-be-glyph-advance test-be-num-glyphs
Assisted-by: OpenAI Codex
Correct the ArabicPUATraditional.txt entry for 0xF295 which should be
isolated not final form. Also enable 0xFC43 ligature so the ligature is
actually used.
Fixes https://github.com/harfbuzz/harfbuzz/issues/5984
Add focused API tests for hb_buffer_create_similar() and buffer
configuration persistence across clear/reset. Also exercise public hb_map
copy, equality, hash, update, iteration, keys, and values paths with
order-independent assertions.
Validation:
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer
meson test -C build-tgl-precheck --print-errorlogs --suite api test-map
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer test-map
Assisted-by: OpenAI Codex <codex@openai.com>
Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
* [fontations] Fix OOB write on glyph-name callback with size == 0
The Rust `_hb_fontations_glyph_name()` callback computed
`glyph_name.len().min(size as usize - 1)`. When a caller passed
`size == 0`, `size as usize - 1` underflowed a `usize` to
`usize::MAX`, the `min()` clamp collapsed to `glyph_name.len()`,
and the subsequent `copy_nonoverlapping` / trailing NUL wrote
`glyph_name.len() + 1` bytes into a zero-capacity caller buffer.
This is an out-of-bounds write reachable from the public API
whenever the build was configured with `-Dfontations=enabled`
and the application had called `hb_fontations_font_set_funcs()`.
Short-circuit the `size == 0` case before the subtraction.
Return `true` in that case to match the existing post and CFF1
backends (`hb-ot-post-table.hh`, `hb-ot-cff1-table.hh`), which
both early-out with `return true` on `!buf_len` — the glyph
does have a name; we simply had no buffer to write it into.
Regression tests added in `test/api/test-glyph-names.c` cover
the zero-size path on post and CFF1 backends, a sub-font, a
NULL buffer, and `size == 1` / small-buffer / exact-fit cases
so the truncation path does not silently regress.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/5946
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [font] Reject glyph-name lookups with size == 0 at the wrapper
`hb_font_t::get_glyph_name()` previously pre-wrote the trailing
NUL only when `size != 0` but still dispatched to the backend
callback with `size == 0`. Every current glyph-name backend has
to re-validate that argument: `post` and `cff1` short-circuit
with `return true`, the new Rust `fontations` callback now
short-circuits too (prior commit), and the CoreText callback in
`hb-coretext-font.cc` has a structurally similar `(CFIndex)size
- 1` pattern.
Normalize this at the wrapper layer: return `false` immediately
on `size == 0`, before any backend dispatch and before the
`*name = '\0'` write. This makes the zero-size case a single,
auditable no-op for every glyph-name provider (native or Rust,
current or future) and removes the CoreText underflow from the
reachable surface through the same chokepoint.
Observable change: callers that invoked
`hb_font_get_glyph_name(font, gid, buf, 0)` on post/cff1 backed
fonts used to get `true` back; they now get `false`. `size == 0`
queries carry no useful information for the caller, so this is
considered a safe hardening rather than a contract break.
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [font] Preserve glyph-name zero-size probe semantics
Keep `hb_font_get_glyph_name(..., NULL, 0)` as a valid
return-value-only probe instead of rejecting `size == 0` in the
wrapper.
Fix the remaining backend-specific zero-size paths in hb-ft and
hb-coretext-font so they answer the probe without dereferencing the
caller buffer, and update the API tests to assert the preserved
behavior.
Testing: CCACHE_DISABLE=1 meson test -C build test-glyph-names
Testing: CCACHE_DISABLE=1 meson test -C build test-ft
Assisted-by: OpenAI Codex <codex@openai.com>
---------
Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
push_clip_glyph kept a hash + linear-scan cache of emitted
clip paths to dedup repeated clip-glyph uses within a single
COLRv1 paint tree. With paint contexts being one-glyph per
use, the cache mostly churned; it also made hb_memcmp trip
on sanitizer-null when an empty path matched an equally-empty
existing entry (fuzzer-reached null-deref).
Drop the cache: always emit a fresh <path> + <clipPath> pair
per push_clip_glyph. Removes defined_paths / content_entry_t
from the paint struct.
Regenerate the two handwriting COLR expected SVGs whose
clip-reuse now produces distinct path defs.
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
include_point used to flip Y so the computed line-box extents
matched the old Y-down internal model. With the library now
tracking extents in Y-up (font) space and wrapping SVG body
in <g transform="scale(1,-1)">, that flip sent the auto-fit
viewBox above the glyph ink instead of around it.
Regenerate the vector expected SVGs that had captured the
shifted viewBox.
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SVG render now wraps all body content in a single
<g transform="scale(1,-1)">. All coordinates inside are
in Y-up (font) space. The viewBox maps the flipped range.
This eliminates:
- Per-path scale(1,-1) wrappers in draw flush_path_svg
- Per-glyph Y-flip in paint _glyph_impl's push_transform
- The {-xy, -yy, -ty} negation in extents transforms
- Format switch in paint _glyph_impl
paint _glyph_impl now passes the raw transform to
push_transform — no format knowledge needed.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove content-based color glyph dedup from paint — no more
<defs>/<use> for color glyphs. Each glyph's paint output is
emitted inline, wrapped by push_transform/pop_transform from
the paint funcs (which emit <g transform="..."> for SVG and
q cm ... Q for PDF).
_glyph_impl is now format-agnostic: extend extents,
push_transform, paint, pop_transform.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove format switch from _glyph_or_fail — it now just extends
extents, calls hb_font_draw_glyph with the context's own funcs,
and flushes. All format-specific work is in flush_path() and
the draw callbacks.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Draw SVG output is now flat inline <path> elements — no
<defs>, no <use>, no id references. Each glyph is an
independent <path d="..." transform="..." fill="..."/>.
Remove hb_vector_draw_set_svg_prefix / get_svg_prefix since
draw output no longer emits any ids. Paint keeps svg_prefix
for gradient and clip ids which SVG requires.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
Replace glyph-ID-based dedup with content-based dedup for SVG
path definitions and color glyph groups. Path/paint output is
hashed and compared byte-for-byte against existing defs;
identical content reuses the same def regardless of glyph ID.
This eliminates the font reference held by draw/paint contexts
(cached_font + hb_font_reference), which was keeping the font
and its face alive longer than the caller expected. No font
pointer is stored at all now.
Also removes changed() — with content-based dedup, foreground
and palette changes produce different content that naturally
won't match cached entries.
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>
Scale all SVG paint and draw coordinates by 1/scale_factor
so paths, clips, gradients, transforms, and images emit
fractional pixel values instead of font-scale integers.
The per-glyph <use> transform now applies only a Y-flip
(scale(1,-1)) instead of scale(1/sf,-1/sf), since the
content is already in output-space.
Revert the 1000000 fill rect bandaid back to 32767 — in
output-space, 32767 pixels is always large enough.
SVG paint callbacks:
- push_clip_glyph: path sink divides by scale_factor
- push_clip_rectangle: coords divided by sx/sy
- push_transform: translation (dx,dy) divided by sx/sy
- gradient coords: divided by sx/sy
- sweep center: divided by sx/sy
- image extents: divided by sx/sy
SVG draw:
- Glyph outline path sink divides by scale_factor
Regenerated all vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SVG and PDF paint backends use large clipped rectangles
to fill solid colors and gradient backgrounds. The old
constant 32767 was sized for upem-space coordinates (~2048
max). After the pixel-space change, coordinates can be in
font-scale (upem * SCALE, e.g. 131072 for a 2048-upem font
at SCALE=64). Values above 32767 fell outside the fill
rect, causing COLRv0 glyph layers to be clipped at the top.
Bump all instances to 1000000 as a bandaid; proper fix is
to emit paint coordinates in output-space.
Regenerated vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>