Commit Graph
69 Commits
Author SHA1 Message Date
Behdad Esfahbod d997502000 [meson] Guard tests for disabled optional libraries (#6335)
* [meson] Skip vector tests when vector is disabled

The vector budget test was built unconditionally even when vector was
explicitly disabled. Its empty dependency supplied neither include paths
nor libraries, breaking otherwise valid reduced-feature builds.

Skip the vector test directory when the library is disabled. Add a Linux
CI build and test pass with vector disabled to cover this configuration.

Reproduced the missing hb.h failure on Linux before the fix. The full
suite with vector, raster, and GPU disabled passed 229 tests with one
skip; all three vector tests passed with vector enabled.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6277
Assisted-by: OpenAI Codex <codex@openai.com>

* [ci] Remove extra vector-disabled build pass

Keep the fix focused on guarding the vector test directory without adding
another build and test pass to the Linux workflow.

CI-only change; the previously validated Meson guard is unchanged.

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

* [meson] Guard dependency fuzzers when subset is disabled

With experimental APIs enabled, dependency fuzzers referenced
libharfbuzz_subset even when the subset library was disabled, causing
Meson setup to fail with an unknown-variable error.

Require subset support when building the dependency fuzzers and when
registering their tests.

Full tests with experimental APIs enabled: 92 passed with subset
disabled, and 247 passed with subset enabled. Both dependency fuzzers
and their 13 tests remain registered in the enabled configuration.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-07 12:55:53 -06:00
Behdad Esfahbod 7584482381 [test] Isolate Noto Nastaliq depend parity tests
The Noto Nastaliq fixtures dominate the runtime of a 64-font dependency
closure-parity chunk, obscuring both their cost and the runtime of the
remaining fixtures.

Run each Noto Nastaliq font as its own named test while retaining the
same seed and per-font test count. Keep all other fonts in the normal
chunking flow.

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

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 16:14:40 -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 bf60bb7460 [test] Restore default fuzzing timeouts
The explicit 120-second timeouts were added after raster-fuzzer chunks
exceeded Meson's 30-second default under MALLOC_PERTURB_.  The dominant
cost was an oversized temporary PNG decode buffer, which is now rejected
before allocation.

Restore the default timeout so future runaway fuzz inputs fail promptly
instead of being hidden by extra headroom.

This reverts commit fbdac41be3.

Testing: meson test -C build

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-08-19 13:12:32 -06:00
Behdad Esfahbod fbdac41be3 [test] Raise timeout of chunked fuzzing tests to 120s
The raster-fuzzer chunks occasionally hit meson's default 30s test
timeout on CI (e.g. raster-fuzzer-chunk-5 at 30.8s on linux main).

The dominant cost is not the fuzzer inputs themselves: meson runs
tests with MALLOC_PERTURB_ set, which makes glibc scribble over
every allocation on free.  Fuzz inputs that acquire large raster
surfaces (up to 4096^2, 64MB) normally leave most pages untouched,
but the perturbation forces a full memset and page-in on free, so a
chunk that runs in ~1.1s bare takes ~7.7s under meson locally
(~6s of it system time), and brushes 30s on slower shared CI
runners.  Which chunk is affected varies by machine because the
fonts glob is not sorted, so chunk membership differs.

Keep the perturbation (it catches real bugs) and raise the timeout
of the chunked fuzzing tests to 120s instead, in line with other
suites (subset: 500, threads: 300, perf: 100).

Fuzzing suite passes.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 15:21:24 -06:00
Khaled Hosny 9d7bba088a Try to fix msan bot (#6124)
* [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.
2026-07-30 19:02:25 -06:00
Behdad Esfahbod c6c9c7c53f [test] Bound depend parity fuzzer runtime
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
2026-07-14 11:56:05 -06:00
Skef IterumandClaude Sonnet 4.6 0cf8d384b5 [depend] Address review feedback: typedef depend contexts, fix fuzzer font set
- 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>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 9a5d99f850 [depend] Address review feedback: preprocessor guards, minor API and naming fixes
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>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude 3648c61cb0 Fix CI: Only build depend fuzzers when depend_api is enabled
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude f62ac68532 Convert parity checker to use glib option parsing
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>
2026-06-05 15:09:11 -07:00
Skef Iterum 83b887cda1 Rename depend fuzzers and add security fuzzer
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.
2026-06-05 15:09:11 -07:00
Skef Iterum 29cf3aa519 Add depend API: graph extraction with contextual filtering
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.
2026-06-05 15:09:11 -07:00
Behdad EsfahbodandClaude Opus 4.6 89ef51691b [gpu] Add GPU encode fuzzer
Encodes up to 16 glyphs per fuzzed font input, exercising
draw accumulation, cu2qu, encode, extents, and blob recycling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 15:18:47 -06:00
Khaled Hosny b54f2212f1 Don’t build raster and vector fuzzers if the library is disabled
Fixes https://github.com/harfbuzz/harfbuzz/issues/5821
2026-03-11 16:05:12 +02:00
Behdad Esfahbod e73a690d9e Remove hb-set-fuzzer 2026-03-10 01:41:46 -03:00
Behdad Esfahbod b18092024a Add raster and vector fuzzers 2026-03-09 22:13:03 -03:00
Khaled Hosny b91d4b8d75 Add meson options to disable building harfbuzz-subset 2026-03-04 18:12:45 +02:00
Behdad Esfahbod ba309a1826 [test/fuzzing] Port all to TAP 2025-04-06 13:54:47 -06:00
Behdad Esfahbod 58d7ab2d59 [meson] Remove unneeded dependencies 2025-04-06 13:42:13 -06:00
Behdad Esfahbod 2b5ae9dec3 [meson] Use a glob.py instead of ls / dir 2025-04-06 12:52:31 -06:00
Behdad Esfahbod b2179dcfcd [meson.build] Another try 2025-04-06 03:03:41 -06:00
Behdad Esfahbod a777a9c535 [meson.build] Try fix using of find 2025-04-06 02:47:06 -06:00
Behdad Esfahbod e332777763 [fuzzing/subset] Make TAP protocol 2025-04-06 02:34:48 -06:00
Behdad Esfahbod 740a103ba1 [meson] See if this fixes bots 2025-04-06 02:34:48 -06:00
Behdad Esfahbod fbda749bdb [meson.build] Try to bring down required version
range() not found
2025-04-06 02:34:48 -06:00
Behdad Esfahbod da5a9fb860 [meson.build] Remove unused fs module 2025-04-06 02:34:48 -06:00
Behdad Esfahbod 1db93d2f6d [test/fuzzing/subset] Run chunks in parallel 2025-04-06 02:34:48 -06:00
Behdad Esfahbod db953a43d0 [meson.build] Cosmetic 2025-04-06 02:34:48 -06:00
Khaled Hosny 7ba3efa5c6 [tests/fuzzing] Use the correct dirs for subset and repacker fuzzers 2025-02-09 18:42:45 +02:00
Khaled Hosny 4c43fdcd07 [test/fuzzing] Simplify Python scripts further
We always path the fuzzer path in meson, so we don’t need to search for
fuzzer path in the scripts, and then we can use one script for all the
fuzzers.
2025-02-09 18:11:34 +02:00
Behdad Esfahbod be22e43d7d [test/fuzzing] Run each fuzzer on all fonts in one process
Much much faster, specially under valgrind, than spawning one process per font.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5061
2025-02-09 14:55:44 +00:00
Behdad Esfahbod 6738ee3d1b [ci/fedora-valgrind] Add time multiplier of 10 and run slow tests 2025-02-09 13:50:27 +00:00
Behdad Esfahbod fc4d507770 [hb-draw-fuzzer] Increase test time
I'm getting timeouts. Might be an infinite loop. But let's see.
2025-02-09 13:28:45 +00:00
Behdad Esfahbod cb6779f9e5 [test] Try running slow tests early
Probably already happens, but this wouldn't hurt.

https://github.com/harfbuzz/harfbuzz/issues/4153#issuecomment-2646125367
2025-02-09 08:39:03 +00:00
Garret Rieger 5a6f5922dd [repacker] Promote repacking API to stable.
For #227.
2025-01-07 11:28:38 -07:00
Garret Rieger 16f61a1c87 [repacker] only build repacker fuzzer when experimental api is enabled. 2022-12-02 00:02:14 +00:00
Garret Rieger 88d437525f [repacker] add test for repacker fuzzer. 2022-12-01 20:17:40 +00:00
Garret Rieger 985b19f678 [repacker] begin implementing a fuzzer for the repacker api. 2022-12-01 20:17:39 +00:00
Khaled Hosny 69d8f27c69 [meson] Require 0.55.0
We implicitly require it for building ragel subproject. This new version
requirement should satisfied in both Fedora 33 and Debian bullseye, and
not be too cutting edge for us.
2021-11-22 03:11:36 +02:00
Khaled Hosny f2d08578e7 [tests] Increase shape-fuzzer timeout 2021-03-16 01:15:40 +02:00
Khaled Hosny 84dd65a874 [test] Remove timeout from test runners
See https://github.com/harfbuzz/harfbuzz/issues/2707#issuecomment-707744079

This wasn’t inconsistent as well, HB_TEST_SUBSET_FUZZER_TIMEOUT defaulted
to 12 in the test runner, but it was overridden to 50 in meson.build,
and then meson has its own test timeout.
2020-10-15 00:49:02 -07:00
Ebrahim Byagowi 6e32145dc9 [meson] Make compatbile with 0.47.0 2020-08-13 18:28:42 +04:30
Ebrahim Byagowi c33e8006fd [fuzz] Implement failing allocator 2020-07-29 07:35:34 +04:30
Ebrahim Byagowi 5c46683ab8 [fuzz] increase shape fuzzer timeout
as https://circleci.com/gh/harfbuzz/harfbuzz/149203
2020-07-22 17:23:22 +04:30
Ebrahim Byagowi cd6f62d960 [meson] Raise timeout value of subset fuzzer testcases
happens when tsan is enabled
2020-07-12 23:05:11 +04:30
Ebrahim Byagowi e04050e3b8 [meson] split fuzzer_ldflags before use 2020-07-08 01:06:30 +04:30
Ebrahim Byagowi c5def34730 [meson] don't underscorify fuzzers names 2020-07-06 23:51:52 +04:30
Ebrahim Byagowi d608f2ac85 [meson] Add fuzzer_ldflags
As ots, https://github.com/khaledhosny/ots/commit/4d37b9b
2020-07-06 23:51:52 +04:30
Ebrahim Byagowi 47a0fbec31 [meson] Mark longer tests with slow
So one can skip them easily by `meson test -Cbuild --no-suite slow`
2020-06-21 08:47:10 +04:30