ClipList::subset() walked startGlyphID..endGlyphID of every ClipRecord, which is only O(num_glyphs) overall when the records are sorted and disjoint. ClipList::sanitize() checks neither, so R overlapping records each spanning all glyphs cost R x 65535 iterations: a 332 KB font with 10000 whole-range records took about 20 s of CPU in hb-subset whatever glyphs or text the request asked for. Invert the loop: iterate the retained glyph set once and find each glyph's record with clips.as_array ().bsearch (gid), exactly how ClipList::get_extents() resolves a glyph's clip box when rendering, and the same shape as the COLRv0 path in COLR::subset(). Cost is now O(|glyphset| log R) regardless of record overlap. For well-formed (sorted, disjoint) lists the output is unchanged; for malformed overlapping/unsorted lists the chosen record can differ (bsearch instead of last-record-wins), which makes the subset agree with the clip box HarfBuzz itself renders from the source font. Adds an extended-format hb-subset-fuzzer input (5000 records covering all 65535 glyphs) that the subset-fuzzer tests pick up. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-MRSCGMJ7. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Security Fuzzers
To build the fuzzers with libFuzzer to perform actual fuzzing, build with:
CXX=clang++ CXXFLAGS="-fsanitize=address,fuzzer-no-link" meson fuzzbuild --default-library=static -Dfuzzer_ldflags="-fsanitize=address,fuzzer"
ninja -Cfuzzbuild
Then, run the fuzzer like this:
fuzzbuild/test/fuzzing/hb-{shape,raster,vector,subset,repacker,depend}-fuzzer [-max_len=2048] [CORPUS_DIR]
Where max_len specifies the maximal length of font files to handle. The smaller the faster.
Note: The depend fuzzer requires -Ddepend_api=true meson option.
For more details consult the following locations:
Depend Closure Parity Test
The hb-depend-closure-parity test is distinct from the security fuzzers.
While security fuzzers test robustness against malformed input, the closure
parity test validates correctness by emulating the glyph closure calculation
used for subsetting with one generated from the dependency graph to avoid
implementation divergence. It should only be run on valid fonts.