11cb0ef41Sopenharmony_ci# JS-Fuzzer 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciJavascript fuzzer for stand-alone shells like D8, Chakra, JSC or Spidermonkey. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciOriginal author: Oliver Chang 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci# Building 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciThis fuzzer may require versions of node that are newer than available on 101cb0ef41Sopenharmony_ciClusterFuzz, so we use [pkg](https://github.com/zeit/pkg) to create a self 111cb0ef41Sopenharmony_cicontained binary) out of this. 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci## Prereqs 141cb0ef41Sopenharmony_ciYou need to intall nodejs and npm. Run `npm install` in this directory. 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci## Fuzzing DB 171cb0ef41Sopenharmony_ciThis fuzzer requires a fuzzing DB. To build one, get the latest `web_tests.zip` 181cb0ef41Sopenharmony_cifrom [gs://clusterfuzz-data/web_tests.zip]( 191cb0ef41Sopenharmony_cihttps://storage.cloud.google.com/clusterfuzz-data/web_tests.zip) and unzip it 201cb0ef41Sopenharmony_ci(note https://crbug.com/v8/10891 for making this data publicly available). 211cb0ef41Sopenharmony_ciThen run: 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci```bash 241cb0ef41Sopenharmony_ci$ mkdir db 251cb0ef41Sopenharmony_ci$ node build_db.js -i /path/to/web_tests -o db chakra v8 spidermonkey WebKit/JSTests 261cb0ef41Sopenharmony_ci``` 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciThis may take a while. Optionally test the fuzzing DB with: 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci```bash 311cb0ef41Sopenharmony_ci$ node test_db.js -i db 321cb0ef41Sopenharmony_ci``` 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci## Building fuzzer 351cb0ef41Sopenharmony_ciThen, to build the fuzzer, 361cb0ef41Sopenharmony_ci```bash 371cb0ef41Sopenharmony_ci$ ./node_modules/.bin/pkg -t node10-linux-x64 . 381cb0ef41Sopenharmony_ci``` 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ciReplace "linux" with either "win" or "macos" for those platforms. 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ciThis builds a binary named `ochang_js_fuzzer` for Linux / macOS OR 431cb0ef41Sopenharmony_ci`ochang_js_fuzzer.exe` for Windows. 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci## Packaging 461cb0ef41Sopenharmony_ciUse `./package.sh`, `./package.sh win` or `./package.sh macos` to build and 471cb0ef41Sopenharmony_cicreate the `output.zip` archive or use these raw commands: 481cb0ef41Sopenharmony_ci```bash 491cb0ef41Sopenharmony_ci$ mkdir output 501cb0ef41Sopenharmony_ci$ cd output 511cb0ef41Sopenharmony_ci$ ln -s ../db db 521cb0ef41Sopenharmony_ci$ ln -s ../ochang_js_fuzzer run 531cb0ef41Sopenharmony_ci$ zip -r /path/output.zip * 541cb0ef41Sopenharmony_ci``` 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci**NOTE**: Add `.exe` to `ochang_js_fuzzer` and `run` filename above if archiving 571cb0ef41Sopenharmony_cifor Windows platform. 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci# Development 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ciRun the tests with: 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci```bash 641cb0ef41Sopenharmony_ci$ npm test 651cb0ef41Sopenharmony_ci``` 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ciWhen test expectations change, generate them with: 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci```bash 701cb0ef41Sopenharmony_ci$ GENERATE=1 npm test 711cb0ef41Sopenharmony_ci``` 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci# Generating exceptional configurations 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ciTests that fail to parse or show very bad performance can be automatically 761cb0ef41Sopenharmony_ciskipped or soft-skipped with the following script (takes >1h): 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci```bash 791cb0ef41Sopenharmony_ci$ WEB_TESTS=/path/to/web_tests OUTPUT=/path/to/output/folder ./gen_exceptions.sh 801cb0ef41Sopenharmony_ci``` 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci# Experimenting (limited to differential fuzzing) 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ciTo locally evaluate the fuzzer, setup a work directory as follows: 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci```bash 871cb0ef41Sopenharmony_ci$ workdir/ 881cb0ef41Sopenharmony_ci$ workdir/app_dir 891cb0ef41Sopenharmony_ci$ workdir/fuzzer 901cb0ef41Sopenharmony_ci$ workdir/input 911cb0ef41Sopenharmony_ci$ workdir/output 921cb0ef41Sopenharmony_ci``` 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ciThe `app_dir` folder can be a symlink or should contain the bundled 951cb0ef41Sopenharmony_civersion of `d8` with all files required for execution. 961cb0ef41Sopenharmony_ciCopy the packaged `ochang_js_fuzzer` executable and the `db` folder 971cb0ef41Sopenharmony_cito the `fuzzer` directory or use a symlink. 981cb0ef41Sopenharmony_ciThe `input` directory is the root folder of the corpus, i.e. pointing 991cb0ef41Sopenharmony_cito the unzipped data of `gs://clusterfuzz-data/web_tests.zip`. 1001cb0ef41Sopenharmony_ciThe `output` directory is expected to be empty. It'll contain all 1011cb0ef41Sopenharmony_cioutput of the fuzzing session. Start the experiments with: 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci```bash 1041cb0ef41Sopenharmony_ci$ # Around ~40000 corresponds to 24h of fuzzing on a workstation. 1051cb0ef41Sopenharmony_ci$ NUM_RUNS = 40000 1061cb0ef41Sopenharmony_ci$ python tools/workbench.py $NUM_RUNS 1071cb0ef41Sopenharmony_ci``` 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ciYou can check current stats with: 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci```bash 1121cb0ef41Sopenharmony_ci$ cat workdir/output/stats.json | python -m json.tool 1131cb0ef41Sopenharmony_ci``` 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ciWhen failures are found, you can forge minimization command lines with: 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci```bash 1181cb0ef41Sopenharmony_ci$ MINIMIZER_PATH = path/to/minimizer 1191cb0ef41Sopenharmony_ci$ python tools/minimize.py $MINIMIZER_PATH 1201cb0ef41Sopenharmony_ci``` 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ciThe path should point to a local checkout of the [minimizer](https://chrome-internal.googlesource.com/chrome/tools/clusterfuzz/+/refs/heads/master/src/python/bot/minimizer/). 123