mirror of
https://github.com/tree-sitter/afl-tree-sitter.git
synced 2026-11-17 03:00:39 +00:00
AFL test harness for tree-sitter runtime and parsers
- C 38.1%
- Shell 35%
- Makefile 22.3%
- Dockerfile 2.9%
- Ruby 0.7%
- Other 1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| afl_in | ||
| dictionaries | ||
| script | ||
| vendor | ||
| .gitignore | ||
| .gitmodules | ||
| afl.c | ||
| afl.h | ||
| afl_go.c | ||
| afl_javascript.c | ||
| afl_ruby.c | ||
| Brewfile | ||
| Dockerfile | ||
| Makefile | ||
| README.md | ||
afl-tree-sitter
afl fuzzing for tree-sitter.
Overview
This project focuses on fuzzing the tree-sitter runtime and associated parsers for each language tree-sitter supports. It does this through a small set of test harnesses, which are C programs—one for each language—that take an input file and (try to) parse it. The test harness, tree-sitter, and the language parsers are all compiled with afl-clang and hardening, after which fuzzing is performed with afl-fuzz.
Getting started
script/bootstrap
script/setup-ramdisk # Optional, but recommended b/c afl is hard on SSDs.
cd /Volumes/ramdisk/
./fuzz javascript
Bugs found so far
An incomplete list of interesting bugs found using afl-fuzz.
tree-sitter runtime
- Handling of invalid UTF8 characters. Not checking return value of
utf8proc_iteratewhich then sets a -1codepoint_refand causes the parser to hang. Fixed in tree-sitter/tree-sitter@f394a48 and test added in tree-sitter/tree-sitter@7092d45. - Infinite loop due to which stack versions are selected for halting. Fixed in tree-sitter/tree-sitter@a94742a .
tree-sitter-ruby
- Infinite loop in external scanner if closing quote is never found due to failure to also check for EOF. Fixed in tree-sitter/tree-sitter-ruby@d5ed995.
Run parallel
You can fuzz in parallel to take full advantage of multi-core systems. See script/fuzz for specific options passed to afl-fuzz and for language setup.
# Fuzz in parallel with 1 primary and 3 secondary fuzzers.
./fuzz -p -n 3 javascript