context_depend_lookup and chain_context_depend_lookup build the input-position glyph sets with for (i = 0; i < inputCount - 1; i++), so a Rule with inputCount 0 (what a null rule offset resolves to) underflows the bound to UINT_MAX and reads past the object into the Null pool. Rewrite both loops as i + 1 < inputCount, matching the guarded inputCount handling used everywhere else in the file. Reached from hb_subset_depend_from_face_or_fail on a crafted GSUB context rule; seed added under test/fuzzing/fonts.
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.