blob: aad48c02529d0a502d557e98959d1c19d962fdf1 [file] [log] [blame] [view]
Hasnain Lakhaniaa183322025-08-25 13:54:33 -07001# Node.js Fuzzing README
2
3The Node.js Thrift implementation uses Jazzer.js for fuzzing. Jazzer.js is a coverage-guided, in-process fuzzer for JavaScript that integrates with libFuzzer.
4
5## Setup
6
71. Install Jazzer.js:
8```bash
9npm install --save-dev @jazzer.js/core
10```
11
12## Available Fuzzers
13
14The Node.js Thrift implementation currently supports the following fuzz targets:
15
16* `fuzz_parse_TJSONProtocol.js` - fuzzes the deserialization of the JSON protocol
17* `fuzz_roundtrip_TJSONProtocol.js` - fuzzes the roundtrip of the JSON protocol (serialize -> deserialize -> compare)
18* `fuzz_parse_TBinaryProtocol.js` - fuzzes the deserialization of the Binary protocol
19* `fuzz_roundtrip_TBinaryProtocol.js` - fuzzes the roundtrip of the Binary protocol
20* `fuzz_parse_TCompactProtocol.js` - fuzzes the deserialization of the Compact protocol
21* `fuzz_roundtrip_TCompactProtocol.js` - fuzzes the roundtrip of the Compact protocol
22
23## Running Fuzzers
24
25To run a fuzzer, use the Jazzer.js CLI:
26
27```bash
28npx jazzer ./fuzz_parse_TJSONProtocol.js --corpus=./corpus
29```
30
31Where:
32- `--corpus` points to a directory containing seed inputs (optional)
33
34## Corpus Generation
35
36You can use the corpus generator from the Rust implementation to generate initial corpus files that can be used with these Node.js fuzzers. For JSON protocol fuzzers, ensure the corpus contains valid JSON data.
37
38## Adding New Fuzzers
39
40To add a new fuzzer:
41
421. Create a new file in the `fuzz` directory
432. Import the appropriate helper functions from `fuzz_common.js`
443. Export a `fuzz` function that takes a Buffer parameter
454. Use either `createParserFuzzer` or `createRoundtripFuzzer` with the appropriate protocol factory
46
47Example:
48```javascript
49const { createParserFuzzer } = require('./fuzz_common');
50
51module.exports.fuzz = createParserFuzzer((transport) => {
52 return new thrift.TJSONProtocol(transport);
53});
54```
55
56For more information about Jazzer.js and its options, see the [Jazzer.js documentation](https://github.com/CodeIntelligenceTesting/jazzer.js).