• Home
Name Date Size #Lines LOC

..--

.github/03-May-2024-261202

agent/03-May-2024-13,2258,557

bazel/03-May-2024-636520

deploy/03-May-2024-1412

docker/03-May-2024-13875

driver/03-May-2024-4,5093,194

examples/03-May-2024-1,456924

sanitizers/03-May-2024-2,4481,603

tests/03-May-2024-967618

third_party/03-May-2024-430390

.bazelrcD03-May-20242.2 KiB5949

.bazelversionD03-May-20249 21

.clang-formatD03-May-202483 87

.gitignoreD03-May-202431 54

Android.bpD03-May-20242.1 KiB6560

BUILD.bazelD03-May-20241.8 KiB8370

CHANGELOG.mdD03-May-20243.5 KiB6452

JazzerSetup.javaD03-May-2024130 66

LICENSED03-May-202411.1 KiB202169

METADATAD03-May-2024499 1917

MODULE_LICENSE_APACHE2D03-May-20240

OWNERSD03-May-202497 65

README.mdD03-May-202435.7 KiB553411

WORKSPACE.bazelD03-May-20244.1 KiB127100

format.shD03-May-2024573 154

init.bzlD03-May-20241.2 KiB3026

jazzer-api.pomD03-May-20241 KiB3833

jazzer_setup.shD03-May-2024184 73

maven.bzlD03-May-20242 KiB4541

maven_install.jsonD03-May-202424.5 KiB429428

repositories.bzlD03-May-20246 KiB150132

README.md

1<img src="https://www.code-intelligence.com/hubfs/Logos/CI%20Logos/Jazzer_einfach.png" height=150px alt="Jazzer logo">
2
3
4# Jazzer
5[![Maven Central](https://img.shields.io/maven-central/v/com.code-intelligence/jazzer-api)](https://search.maven.org/search?q=g:com.code-intelligence%20a:jazzer-api)
6![GitHub Actions](https://github.com/CodeIntelligenceTesting/jazzer/workflows/Build%20all%20targets%20and%20run%20all%20tests/badge.svg)
7[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/java-example.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:java-example)
8
9Jazzer is a coverage-guided, in-process fuzzer for the JVM platform developed by [Code Intelligence](https://code-intelligence.com).
10It is based on [libFuzzer](https://llvm.org/docs/LibFuzzer.html) and brings many of its instrumentation-powered mutation features to the JVM.
11
12The JVM bytecode is executed inside the fuzzer process, which ensures fast execution speeds and allows seamless fuzzing of
13native libraries.
14
15Jazzer currently supports the following platforms:
16* Linux x86_64
17* macOS 10.15+ x86_64 (experimental support for arm64)
18* Windows x86_64
19
20## News: Jazzer available in OSS-Fuzz
21
22[Code Intelligence](https://code-intelligence.com) and Google have teamed up to bring support for Java, Kotlin, and other JVM-based languages to [OSS-Fuzz](https://github.com/google/oss-fuzz), Google's project for large-scale fuzzing of open-souce software. Read [the blogpost](https://security.googleblog.com/2021/03/fuzzing-java-in-oss-fuzz.html) over at the Google Security Blog.
23
24If you want to learn more about Jazzer and OSS-Fuzz, [watch the FuzzCon 2020 talk](https://www.youtube.com/watch?v=SmH3Ys_k8vA&list=PLI0R_0_8-TV55gJU-UXrOzZoPbVOj1CW6&index=3) by [Abhishek Arya](https://twitter.com/infernosec) and [Fabian Meumertzheim](https://twitter.com/fhenneke).
25
26## Getting Jazzer
27
28### Using Docker
29
30The "distroless" Docker image [cifuzz/jazzer](https://hub.docker.com/r/cifuzz/jazzer) includes Jazzer together with OpenJDK 11. Just mount a directory containing your compiled fuzz target into the container under `/fuzzing` by running:
31
32```sh
33docker run -v path/containing/the/application:/fuzzing cifuzz/jazzer <arguments>
34```
35
36If Jazzer produces a finding, the input that triggered it will be available in the same directory.
37
38### Compiling with Bazel
39
40#### Dependencies
41
42Jazzer has the following dependencies when being built from source:
43
44* Bazel 4 or later
45* JDK 8 or later (e.g. [OpenJDK](https://openjdk.java.net/))
46* [Clang](https://clang.llvm.org/) and [LLD](https://lld.llvm.org/) 9.0 or later (using a recent version is strongly recommended)
47
48It is recommended to use [Bazelisk](https://github.com/bazelbuild/bazelisk) to automatically download and install Bazel.
49Simply download the release binary for your OS and architecture and ensure that it is available in the `PATH`.
50The instructions below will assume that this binary is called `bazel` - Bazelisk is a thin wrapper around the actual Bazel binary and can be used interchangeably.
51
52#### Compilation
53
54Assuming the dependencies are installed, build Jazzer from source as follows:
55
56```bash
57$ git clone https://github.com/CodeIntelligenceTesting/jazzer
58$ cd jazzer
59# Note the double dash used to pass <arguments> to Jazzer rather than Bazel.
60$ bazel run //:jazzer -- <arguments>
61```
62
63If you prefer to build binaries that can be run without Bazel, use the following command to build your own archive with release binaries:
64
65```bash
66$ bazel build //:jazzer_release
67...
68INFO: Found 1 target...
69Target //:jazzer_release up-to-date:
70  bazel-bin/jazzer_release.tar.gz
71...
72```
73
74This will print the path of a `jazzer_release.tar.gz` archive that contains the same binaries that would be part of a release.
75
76##### macOS
77
78The build may fail with the clang shipped with Xcode. If you encounter issues during the build, add `--config=toolchain`
79right after `run` or `build` in the `bazelisk` commands above to use a checked-in toolchain that is known to work.
80Alternatively, manually install LLVM and set `CC` to the path of LLVM clang.
81
82#### rules_fuzzing
83
84Support for Jazzer has recently been added to [rules_fuzzing](https://github.com/bazelbuild/rules_fuzzing), the official Bazel rules for fuzzing.
85See their README for instructions on how to use Jazzer in a Java Bazel project.
86
87### Using the provided binaries
88
89Binary releases are available under [Releases](https://github.com/CodeIntelligenceTesting/jazzer/releases),
90but do not always include the latest changes.
91
92The binary distributions of Jazzer consist of the following components:
93
94- `jazzer` - main binary
95- `jazzer_agent_deploy.jar` - Java agent that performs bytecode instrumentation and tracks coverage (automatically loaded by `jazzer`)
96- `jazzer_api_deploy.jar` - contains convenience methods for creating fuzz targets and defining custom hooks
97
98The additional release artifact `examples_deploy.jar` contains most of the examples and can be used to run them without having to build them (see Examples below).
99
100After unpacking the archive, run Jazzer via
101
102```bash
103./jazzer <arguments>
104```
105
106If this leads to an error message saying that `libjvm.so` has not been found, the path to the local JRE needs to be
107specified in the `JAVA_HOME` environment variable.
108
109## Examples
110
111Multiple examples for instructive and real-world Jazzer fuzz targets can be found in the `examples/` directory.
112A toy example can be run as follows:
113
114```bash
115# Using Bazel:
116bazel run //examples:ExampleFuzzer
117# Using the binary release and examples_deploy.jar:
118./jazzer --cp=examples_deploy.jar
119```
120
121This should produce output similar to the following:
122
123```
124INFO: Loaded 1 hooks from com.example.ExampleFuzzerHooks
125INFO: Instrumented com.example.ExampleFuzzer (took 81 ms, size +83%)
126INFO: libFuzzer ignores flags that start with '--'
127INFO: Seed: 2735196724
128INFO: Loaded 1 modules   (65536 inline 8-bit counters): 65536 [0xe387b0, 0xe487b0),
129INFO: Loaded 1 PC tables (65536 PCs): 65536 [0x7f9353eff010,0x7f9353fff010),
130INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
131INFO: A corpus is not provided, starting from an empty corpus
132#2      INITED cov: 2 ft: 2 corp: 1/1b exec/s: 0 rss: 94Mb
133#1562   NEW    cov: 4 ft: 4 corp: 2/14b lim: 17 exec/s: 0 rss: 98Mb L: 13/13 MS: 5 ShuffleBytes-CrossOver-InsertRepeatedBytes-ShuffleBytes-CMP- DE: "magicstring4"-
134#1759   REDUCE cov: 4 ft: 4 corp: 2/13b lim: 17 exec/s: 0 rss: 99Mb L: 12/12 MS: 2 ChangeBit-EraseBytes-
135#4048   NEW    cov: 6 ft: 6 corp: 3/51b lim: 38 exec/s: 0 rss: 113Mb L: 38/38 MS: 4 ChangeBit-ChangeByte-CopyPart-CrossOver-
136#4055   REDUCE cov: 6 ft: 6 corp: 3/49b lim: 38 exec/s: 0 rss: 113Mb L: 36/36 MS: 2 ShuffleBytes-EraseBytes-
137#4266   REDUCE cov: 6 ft: 6 corp: 3/48b lim: 38 exec/s: 0 rss: 113Mb L: 35/35 MS: 1 EraseBytes-
138#4498   REDUCE cov: 6 ft: 6 corp: 3/47b lim: 38 exec/s: 0 rss: 114Mb L: 34/34 MS: 2 EraseBytes-CopyPart-
139#4764   REDUCE cov: 6 ft: 6 corp: 3/46b lim: 38 exec/s: 0 rss: 115Mb L: 33/33 MS: 1 EraseBytes-
140#5481   REDUCE cov: 6 ft: 6 corp: 3/44b lim: 43 exec/s: 0 rss: 116Mb L: 31/31 MS: 2 InsertByte-EraseBytes-
141#131072 pulse  cov: 6 ft: 6 corp: 3/44b lim: 1290 exec/s: 65536 rss: 358Mb
142
143== Java Exception: java.lang.IllegalStateException: mustNeverBeCalled has been called
144        at com.example.ExampleFuzzer.mustNeverBeCalled(ExampleFuzzer.java:38)
145        at com.example.ExampleFuzzer.fuzzerTestOneInput(ExampleFuzzer.java:32)
146DEDUP_TOKEN: eb6ee7d9b256590d
147== libFuzzer crashing input ==
148MS: 1 CMP- DE: "\x00C"-; base unit: 04e0ccacb50424e06e45f6184ad45895b6b8df8f
1490x6d,0x61,0x67,0x69,0x63,0x73,0x74,0x72,0x69,0x6e,0x67,0x34,0x74,0x72,0x69,0x6e,0x67,0x34,0x74,0x69,0x67,0x34,0x7b,0x0,0x0,0x43,0x34,0xa,0x0,0x0,0x0,
150magicstring4tring4tig4{\x00\x00C4\x0a\x00\x00\x00
151artifact_prefix='./'; Test unit written to crash-efea1e8fc83a15217d512e20d964040a68a968c3
152Base64: bWFnaWNzdHJpbmc0dHJpbmc0dGlnNHsAAEM0CgAAAA==
153reproducer_path='.'; Java reproducer written to Crash_efea1e8fc83a15217d512e20d964040a68a968c3.java
154```
155
156Here you can see the usual libFuzzer output in case of a crash, augmented with JVM-specific information.
157Instead of a native stack trace, the details of the uncaught Java exception that caused the crash are printed, followed by the fuzzer input that caused the exception to be thrown (if it is not too long).
158More information on what hooks and Java reproducers are can be found below.
159
160See `examples/BUILD.bazel` for the list of all possible example targets.
161
162## Usage
163
164### Creating a fuzz target
165
166Jazzer requires a JVM class containing the entry point for the fuzzer. This is commonly referred to as a "fuzz target" and
167may be as simple as the following Java example:
168
169```java
170package com.example.MyFirstFuzzTarget;
171
172public class MyFirstFuzzTarget {
173    public static void fuzzerTestOneInput(byte[] input) {
174        ...
175        // Call the function under test with arguments derived from input and
176        // throw an exception if something unwanted happens.
177        ...
178    }
179}
180```
181
182A Java fuzz target class needs to define exactly one of the following functions:
183
184* `public static void fuzzerTestOneInput(byte[] input)`: Ideal for fuzz targets that naturally work on raw byte input (e.g.
185  image parsers).
186* `public static void fuzzerTestOneInput(com.code_intelligence.api.FuzzedDataProvider data)`: A variety of types of "fuzzed
187  data" is made available via the `FuzzedDataProvider` interface (see below for more information on this interface).
188
189The fuzzer will repeatedly call this function with generated inputs. All unhandled exceptions are caught and
190reported as errors.
191
192The optional functions `public static void fuzzerInitialize()` or `public static void fuzzerInitialize(String[] args)`
193can be defined if initial setup is required. These functions will be called once before
194the first call to `fuzzerTestOneInput`.
195
196The optional function `public static void fuzzerTearDown()` will be run just before the JVM is shut down.
197
198#### Kotlin
199
200An example of a Kotlin fuzz target can be found in
201[KlaxonFuzzer.kt](https://github.com/CodeIntelligenceTesting/jazzer/tree/main/examples/src/main/java/com/example/KlaxonFuzzer.kt).
202
203### Running the fuzzer
204
205The fuzz target needs to be compiled and packaged into a `.jar` archive. Assuming that this archive is called
206`fuzz_target.jar` and depends on libraries available as `lib1.jar` and `lib2.jar`, fuzzing is started by
207invoking Jazzer with the following arguments:
208
209```bash
210--cp=fuzz_target.jar:lib1.jar:lib2.jar --target_class=com.example.MyFirstFuzzTarget <optional_corpus_dir>
211```
212
213The fuzz target class can optionally be specified by adding it as the value of the `Jazzer-Fuzz-Target-Class` attribute
214in the JAR's manifest. If there is only a single such attribute among all manifests of JARs on the classpath, Jazzer will
215use its value as the fuzz target class.
216
217Bazel produces the correct type of `.jar` from a `java_binary` target with `create_executable = False` and
218`deploy_manifest_lines = ["Jazzer-Fuzz-Target-Class: com.example.MyFirstFuzzTarget"]` by adding the suffix `_deploy.jar`
219to the target name.
220
221### Fuzzed Data Provider
222
223For most non-trivial fuzz targets it is necessary to further process the byte array passed from the fuzzer, for example
224to extract multiple values or convert the input into a valid `java.lang.String`. We provide functionality similar to
225[atheris'](https://github.com/google/atheris) `FuzzedDataProvider` and libFuzzer's `FuzzedDataProvider.h` to simplify
226the task of writing JVM fuzz targets.
227
228If the function `public static void fuzzerTestOneInput(FuzzedDataProvider data)` is defined in the fuzz target, it will
229be passed an object implementing `com.code_intelligence.jazzer.api.FuzzedDataProvider` that allows _consuming_ the raw fuzzer
230input as values of common types. This can look as follows:
231
232```java
233package com.example.MySecondFuzzTarget;
234
235import com.code_intelligence.jazzer.api.FuzzedDataProvider;
236
237public class MySecondFuzzTarget {
238    public static void callApi(int val, String text) {
239        ...
240    }
241
242    public static void fuzzerTestOneInput(FuzzedDataProvider data) {
243        callApi1(data.consumeInt(), data.consumeRemainingAsString());
244    }
245}
246```
247
248The `FuzzedDataProvider` interface definition is contained in `jazzer_api_deploy.jar` in the binary release and can be
249built by the Bazel target `//agent:jazzer_api_deploy.jar`. It is also available from
250[Maven Central](https://search.maven.org/search?q=g:com.code-intelligence%20a:jazzer-api).
251For additional information, see the
252[javadocs](https://codeintelligencetesting.github.io/jazzer-api/com/code_intelligence/jazzer/api/FuzzedDataProvider.html).
253
254It is highly recommended to use `FuzzedDataProvider` for generating `java.lang.String` objects inside the fuzz target
255instead of converting the raw byte array to directly via a `String` constructor as the `FuzzedDataProvider` implementation is
256engineered to minimize copying and generate both valid and invalid ASCII-only and Unicode strings.
257
258### Autofuzz mode
259
260The Autofuzz mode enables fuzzing arbitrary methods without having to manually create fuzz targets.
261Instead, Jazzer will attempt to generate suitable and varied inputs to a specified methods using only public API functions available on the classpath.
262
263To use Autofuzz, specify the `--autofuzz` flag and provide a fully [qualified method reference](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.13), e.g.:
264```
265--autofuzz=org.apache.commons.imaging.Imaging::getBufferedImage
266```
267To autofuzz a constructor the `ClassType::new` format can be used.
268If there are multiple overloads, and you want Jazzer to only fuzz one, you can optionally specify the signature of the method to fuzz:
269```
270--autofuzz=org.apache.commons.imaging.Imaging::getBufferedImage(java.io.InputStream,java.util.Map)
271```
272The format of the signature agrees with that obtained from the part after the `#` of the link to the Javadocs for the particular method.
273
274Under the hood, Jazzer tries various ways of creating objects from the fuzzer input. For example, if a parameter is an
275interface or an abstract class, it will look for all concrete implementing classes on the classpath.
276Jazzer can also create objects from classes that follow the [builder design pattern](https://www.baeldung.com/creational-design-patterns#builder)
277or have a default constructor and use setters to set the fields.
278
279Creating objects from fuzzer input can lead to many reported exceptions.
280Jazzer addresses this issue by ignoring exceptions that the target method declares to throw.
281In addition to that, you can provide a list of exceptions to be ignored during fuzzing via the `--autofuzz_ignore` flag in the form of a comma-separated list.
282You can specify concrete exceptions (e.g., `java.lang.NullPointerException`), in which case also subclasses of these exception classes will be ignored, or glob patterns to ignore all exceptions in a specific package (e.g. `java.lang.*` or `com.company.**`).
283
284When fuzzing with `--autofuzz`, Jazzer automatically enables the `--keep_going` mode to keep fuzzing indefinitely after the first finding.
285Set `--keep_going=N` explicitly to stop after the `N`-th finding.
286
287#### Docker
288To facilitate using the Autofuzz mode, there is a docker image that you can use to fuzz libraries just by providing their Maven coordinates.
289The dependencies will then be downloaded and autofuzzed:
290
291```sh
292docker run cifuzz/jazzer-autofuzz <Maven coordinates> --autofuzz=<method reference> <further arguments>
293```
294
295As an example, you can autofuzz the `json-sanitizer` library as follows:
296```sh
297docker run -it cifuzz/jazzer-autofuzz \
298   com.mikesamuel:json-sanitizer:1.2.0 \
299   com.google.json.JsonSanitizer::sanitize \
300   --autofuzz_ignore=java.lang.ArrayIndexOutOfBoundsException \
301   --keep_going=1
302```
303
304####
305
306### Reproducing a bug
307
308When Jazzer manages to find an input that causes an uncaught exception or a failed assertion, it prints a Java
309stack trace and creates two files that aid in reproducing the crash without Jazzer:
310
311* `crash-<sha1_of_input>` contains the raw bytes passed to the fuzz target (just as with libFuzzer C/C++ fuzz targets).
312  The crash can be reproduced with Jazzer by passing the path to the crash file as the only positional argument.
313* `Crash-<sha1_of_input>.java` contains a class with a `main` function that invokes the fuzz target with the
314  crashing input. This is especially useful if using `FuzzedDataProvider` as the raw bytes of the input do not
315  directly correspond to the values consumed by the fuzz target. The `.java` file can be compiled with just
316  the fuzz target and its dependencies in the classpath (plus `jazzer_api_deploy.jar` if using `FuzzedDataProvider).
317
318### Minimizing a crashing input
319
320Every crash stack trace is accompanied by a `DEDUP_TOKEN` that uniquely identifies the relevant parts of the stack
321trace. This value is used by libFuzzer while minimizing a crashing input to ensure that the smaller inputs reproduce
322the "same" bug. To minimize a crashing input, execute Jazzer with the following arguments in addition to `--cp` and
323`--target_class`:
324
325```bash
326-minimize_crash=1 <path/to/crashing_input>
327```
328
329### Parallel execution
330
331libFuzzer offers the `-fork=N` and `-jobs=N` flags for parallel fuzzing, both of which are also supported by Jazzer.
332
333### Limitations
334
335Jazzer currently maintains coverage information in a global variable that is shared among threads. This means that while
336fuzzing multi-threaded fuzz targets is theoretically possible, the reported coverage information may be misleading.
337
338## Findings
339
340Jazzer has so far uncovered the following vulnerabilities and bugs:
341
342| Project | Bug      | Status | CVE | found by |
343| ------- | -------- | ------ | --- | -------- |
344| [OpenJDK](https://github.com/openjdk/jdk) | `OutOfMemoryError` via a small BMP image | [fixed](https://openjdk.java.net/groups/vulnerability/advisories/2022-01-18) | [CVE-2022-21360](https://nvd.nist.gov/vuln/detail/CVE-2022-21360) | [Code Intelligence](https://code-intelligence.com) |
345| [OpenJDK](https://github.com/openjdk/jdk) | `OutOfMemoryError` via a small TIFF image | [fixed](https://openjdk.java.net/groups/vulnerability/advisories/2022-01-18) | [CVE-2022-21366](https://nvd.nist.gov/vuln/detail/CVE-2022-21366) | [Code Intelligence](https://code-intelligence.com) |
346| [protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) | Small protobuf messages can consume minutes of CPU time | [fixed](https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-wrvw-hg22-4m67) | [CVE-2021-22569](https://nvd.nist.gov/vuln/detail/CVE-2021-22569) | [OSS-Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=39330) |
347| [jhy/jsoup](https://github.com/jhy/jsoup) | More than 19 Bugs found in HTML and XML parser | [fixed](https://github.com/jhy/jsoup/security/advisories/GHSA-m72m-mhq2-9p6c) | [CVE-2021-37714](https://nvd.nist.gov/vuln/detail/CVE-2021-37714) | [Code Intelligence](https://code-intelligence.com) |
348| [Apache/commons-compress](https://commons.apache.org/proper/commons-compress/) | Infinite loop when loading a crafted 7z | fixed | [CVE-2021-35515](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-35515) | [Code Intelligence](https://code-intelligence.com) |
349| [Apache/commons-compress](https://commons.apache.org/proper/commons-compress/) | `OutOfMemoryError` when loading a crafted 7z | fixed | [CVE-2021-35516](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-35516) | [Code Intelligence](https://code-intelligence.com) |
350| [Apache/commons-compress](https://commons.apache.org/proper/commons-compress/) | Infinite loop when loading a crafted TAR | fixed | [CVE-2021-35517](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-35517) | [Code Intelligence](https://code-intelligence.com) |
351| [Apache/commons-compress](https://commons.apache.org/proper/commons-compress/) | `OutOfMemoryError` when loading a crafted ZIP | fixed | [CVE-2021-36090](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-36090) | [Code Intelligence](https://code-intelligence.com) |
352| [Apache/PDFBox](https://pdfbox.apache.org/) | Infinite loop when loading a crafted PDF | fixed | [CVE-2021-27807](https://cve.mitre.org/cgi-bin/cvename.cgi?name=2021-27807) | [Code Intelligence](https://code-intelligence.com) |
353| [Apache/PDFBox](https://pdfbox.apache.org/) | OutOfMemoryError when loading a crafted PDF | fixed | [CVE-2021-27906](https://cve.mitre.org/cgi-bin/cvename.cgi?name=2021-27906) | [Code Intelligence](https://code-intelligence.com) |
354| [netplex/json-smart-v1](https://github.com/netplex/json-smart-v1) <br/> [netplex/json-smart-v2](https://github.com/netplex/json-smart-v2) | `JSONParser#parse` throws an undeclared exception | [fixed](https://github.com/netplex/json-smart-v2/issues/60) | [CVE-2021-27568](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-27568) | [@GanbaruTobi](https://github.com/GanbaruTobi) |
355| [OWASP/json-sanitizer](https://github.com/OWASP/json-sanitizer) | Output can contain`</script>` and `]]>`, which allows XSS | [fixed](https://groups.google.com/g/json-sanitizer-support/c/dAW1AeNMoA0) | [CVE-2021-23899](https://cve.mitre.org/cgi-bin/cvename.cgi?name=2021-23899) | [Code Intelligence](https://code-intelligence.com) |
356| [OWASP/json-sanitizer](https://github.com/OWASP/json-sanitizer) | Output can be invalid JSON and undeclared exceptions can be thrown | [fixed](https://groups.google.com/g/json-sanitizer-support/c/dAW1AeNMoA0) | [CVE-2021-23900](https://cve.mitre.org/cgi-bin/cvename.cgi?name=2021-23900) | [Code Intelligence](https://code-intelligence.com) |
357| [alibaba/fastjon](https://github.com/alibaba/fastjson) | `JSON#parse` throws undeclared exceptions | [fixed](https://github.com/alibaba/fastjson/issues/3631) | | [Code Intelligence](https://code-intelligence.com) |
358| [Apache/commons-compress](https://commons.apache.org/proper/commons-compress/) | Infinite loop and `OutOfMemoryError` in `TarFile` | [fixed](https://issues.apache.org/jira/browse/COMPRESS-569) | | [Code Intelligence](https://code-intelligence.com) |
359| [Apache/commons-compress](https://commons.apache.org/proper/commons-compress/) | `NullPointerException` in `ZipFile`| [fixed](https://issues.apache.org/jira/browse/COMPRESS-568) | | [Code Intelligence](https://code-intelligence.com) |
360| [Apache/commons-imaging](https://commons.apache.org/proper/commons-imaging/) | Parsers for multiple image formats throw undeclared exceptions | [reported](https://issues.apache.org/jira/browse/IMAGING-279?jql=project%20%3D%20%22Commons%20Imaging%22%20AND%20reporter%20%3D%20Meumertzheim%20) | | [Code Intelligence](https://code-intelligence.com) |
361| [Apache/PDFBox](https://pdfbox.apache.org/) | Various undeclared exceptions | [fixed](https://issues.apache.org/jira/browse/PDFBOX-5108?jql=project%20%3D%20PDFBOX%20AND%20reporter%20in%20(Meumertzheim)) | | [Code Intelligence](https://code-intelligence.com) |
362| [cbeust/klaxon](https://github.com/cbeust/klaxon) | Default parser throws runtime exceptions | [fixed](https://github.com/cbeust/klaxon/pull/330) | | [Code Intelligence](https://code-intelligence.com) |
363| [FasterXML/jackson-dataformats-binary](https://github.com/FasterXML/jackson-dataformats-binary) | `CBORParser` throws an undeclared exception due to missing bounds checks when parsing Unicode | [fixed](https://github.com/FasterXML/jackson-dataformats-binary/issues/236) | | [Code Intelligence](https://code-intelligence.com) |
364| [FasterXML/jackson-dataformats-binary](https://github.com/FasterXML/jackson-dataformats-binary) | `CBORParser` throws an undeclared exception on dangling arrays | [fixed](https://github.com/FasterXML/jackson-dataformats-binary/issues/240) | | [Code Intelligence](https://code-intelligence.com) |
365| [ngageoint/tiff-java](https://github.com/ngageoint/tiff-java) | `readTiff ` Index Out Of Bounds | [fixed](https://github.com/ngageoint/tiff-java/issues/38) | | [@raminfp](https://github.com/raminfp) |
366| [google/re2j](https://github.com/google/re2j) | `NullPointerException` in `Pattern.compile` | [reported](https://github.com/google/re2j/issues/148) | | [@schirrmacher](https://github.com/schirrmacher) |
367| [google/gson](https://github.com/google/gson) | `ArrayIndexOutOfBounds` in `ParseString` | [fixed](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40838) | | [@DavidKorczynski](https://twitter.com/Davkorcz) |
368
369As Jazzer is used to fuzz JVM projects in OSS-Fuzz, an additional list of bugs can be found [on the OSS-Fuzz issue tracker](https://bugs.chromium.org/p/oss-fuzz/issues/list?q=proj%3A%22json-sanitizer%22%20OR%20proj%3A%22fastjson2%22%20OR%20proj%3A%22jackson-core%22%20OR%20proj%3A%22jackson-dataformats-binary%22%20OR%20proj%3A%22jackson-dataformats-xml%22%20OR%20proj%3A%22apache-commons%22%20OR%20proj%3A%22jsoup%22%20OR%20proj%3A%22apache-commons-codec%22%20OR%20proj%3A%22apache-commons-io%22%20OR%20proj%3A%22apache-commons-jxpath%22%20OR%20proj%3A%22apache-commons-lang%22%20OR%20proj%3A%22httpcomponents-client%22%20OR%20proj%3A%22httpcomponents-core%22%20OR%20proj%3A%22tomcat%22%20OR%20proj%3A%22archaius-core%22%20OR%20proj%3A%22bc-java%22%20OR%20proj%3A%22gson%22%20OR%20proj%3A%22guava%22%20OR%20proj%3A%22guice%22%20OR%20proj%3A%22hdrhistogram%22%20OR%20proj%3A%22jackson-databind%22%20OR%20proj%3A%22javassist%22%20OR%20proj%3A%22jersey%22%20OR%20proj%3A%22jettison%22%20OR%20proj%3A%22joda-time%22%20OR%20proj%3A%22jul-to-slf4j%22%20OR%20proj%3A%22logback%22%20OR%20proj%3A%22servo-core%22%20OR%20proj%3A%22slf4j-api%22%20OR%20proj%3A%22snakeyaml%22%20OR%20proj%3A%22spring-boot-actuator%22%20OR%20proj%3A%22spring-boot%22%20OR%20proj%3A%22spring-framework%22%20OR%20proj%3A%22spring-security%22%20OR%20proj%3A%22stringtemplate4%22%20OR%20proj%3A%22woodstox%22%20OR%20proj%3A%22xmlpulll%22%20OR%20proj%3A%22xstream%22&can=1).
370
371If you find bugs with Jazzer, we would like to hear from you!
372Feel free to [open an issue](https://github.com/CodeIntelligenceTesting/jazzer/issues/new) or submit a pull request.
373
374## Advanced Options
375
376Various command line options are available to control the instrumentation and fuzzer execution. Since Jazzer is a
377libFuzzer-compiled binary, all positional and single dash command-line options are parsed by libFuzzer. Therefore, all
378Jazzer options are passed via double dash command-line flags, i.e., as `--option=value` (note the `=` instead of a space).
379
380A full list of command-line flags can be printed with the `--help` flag. For the available libFuzzer options please refer
381to [its documentation](https://llvm.org/docs/LibFuzzer.html) for a detailed description.
382
383### Passing JVM arguments
384
385When Jazzer is launched, it starts a JVM in which it executes the fuzz target.
386Arguments for this JVM can be provided via the `JAVA_OPTS` environment variable.
387
388Alternatively, arguments can also be supplied via the `--jvm_args` argument.
389Multiple arguments are delimited by the classpath separator, which is `;` on Windows and `:` else.
390For example, to enable preview features as well as set a maximum heap size, add the following to the Jazzer invocation:
391
392```bash
393# Windows
394--jvm_args=--enable-preview;-Xmx1000m
395# Linux & macOS
396--jvm_args=--enable-preview:-Xmx1000m
397```
398
399Arguments specified with `--jvm_args` take precendence over those in `JAVA_OPTS`.
400
401### Coverage Instrumentation
402
403The Jazzer agent inserts coverage markers into the JVM bytecode during class loading. libFuzzer uses this information
404to guide its input mutations towards increased coverage.
405
406It is possible to restrict instrumentation to only a subset of classes with the `--instrumentation_includes` flag. This
407is especially useful if coverage inside specific packages is of higher interest, e.g., the user library under test rather than an
408external parsing library in which the fuzzer is likely to get lost. Similarly, there is `--instrumentation_excludes` to
409exclude specific classes from instrumentation. Both flags take a list of glob patterns for the java class name separated
410by colon:
411
412```bash
413--instrumentation_includes=com.my_com.**:com.other_com.** --instrumentation_excludes=com.my_com.crypto.**
414```
415
416By default, JVM-internal classes and Java as well as Kotlin standard library classes are not instrumented, so these do not
417need to be excluded manually.
418
419### Trace Instrumentation
420
421The agent adds additional hooks for tracing compares, integer divisions, switch statements and array indices.
422These hooks correspond to [clang's data flow hooks](https://clang.llvm.org/docs/SanitizerCoverage.html#tracing-data-flow).
423The particular instrumentation types to apply can be specified using the `--trace` flag, which accepts the following values:
424
425* `cov`: AFL-style edge coverage
426* `cmp`: compares (int, long, String) and switch cases
427* `div`: divisors in integer divisions
428* `gep`: constant array indexes
429* `indir`: call through `Method#invoke`
430* `all`: shorthand to apply all available instrumentations (except `gep`)
431
432Multiple instrumentation types can be combined with a colon (Linux, macOS) or a semicolon (Windows).
433
434### Value Profile
435
436The run-time flag `-use_value_profile=1` enables [libFuzzer's value profiling mode](https://llvm.org/docs/LibFuzzer.html#value-profile).
437When running with this flag, the feedback about compares and constants received from Jazzer's trace instrumentation is
438associated with the particular bytecode location and used to provide additional coverage instrumentation.
439See [ExampleValueProfileFuzzer.java](https://github.com/CodeIntelligenceTesting/jazzer/tree/main/examples/src/main/java/com/example/ExampleValueProfileFuzzer.java)
440for a fuzz target that would be very hard to fuzz without value profile.
441
442### Custom Hooks
443
444In order to obtain information about data passed into functions such as `String.equals` or `String.startsWith`, Jazzer
445hooks invocations to these methods. This functionality is also available to fuzz targets, where it can be used to implement
446custom sanitizers or stub out methods that block the fuzzer from progressing (e.g. checksum verifications or random number generation).
447See [ExampleFuzzerHooks.java](https://github.com/CodeIntelligenceTesting/jazzer/tree/main/examples/src/main/java/com/example/ExampleFuzzerHooks.java)
448for an example of such a hook. An example for a sanitizer can be found in
449[ExamplePathTraversalFuzzerHooks.java](https://github.com/CodeIntelligenceTesting/jazzer/tree/main/examples/src/main/java/com/example/ExamplePathTraversalFuzzerHooks.java).
450
451Method hooks can be declared using the `@MethodHook` annotation defined in the `com.code_intelligence.jazzer.api` package,
452which is contained in `jazzer_api_deploy.jar` (binary release) or built by the target `//agent:jazzer_api_deploy.jar` (Bazel).
453It is also available from
454[Maven Central](https://search.maven.org/search?q=g:com.code-intelligence%20a:jazzer-api).
455See the [javadocs of the `@MethodHook` API](https://codeintelligencetesting.github.io/jazzer-api/com/code_intelligence/jazzer/api/MethodHook.html)
456for more details.
457
458To use the compiled method hooks they have to be available on the classpath provided by `--cp` and can then be loaded by providing the
459flag `--custom_hooks`, which takes a colon-separated list of names of classes to load hooks from.
460If a hook is meant to be applied to a class in the Java standard library, it has to be loaded from a JAR file so that Jazzer can [add it to the bootstrap class loader search](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#appendToBootstrapClassLoaderSearch-java.util.jar.JarFile-).
461This list of custom hooks can alternatively be specified via the `Jazzer-Hook-Classes` attribute in the fuzz target
462JAR's manifest.
463
464### Suppressing stack traces
465
466With the flag `--keep_going=N` Jazzer continues fuzzing until `N` unique stack traces have been encountered.
467
468Particular stack traces can also be ignored based on their `DEDUP_TOKEN` by passing a comma-separated list of tokens
469via `--ignore=<token_1>,<token2>`.
470
471### Export coverage information
472
473The internally gathered JaCoCo coverage information can be exported in human-readable and JaCoCo execution data format
474(`.exec`). These can help identify code areas that have not been covered by the fuzzer and thus may require more
475comprehensive fuzz targets or a more extensive initial corpus to reach.
476
477The human-readable report contains coverage information, like branch and line coverage, on file level. It's useful to
478get a quick overview about the overall coverage. The flag `--coverage_report=<file>` can be used to generate it.
479
480Similar to the JaCoCo `dump` command, the flag `--coverage_dump=<file>` specifies a coverage dump file, often called
481`jacoco.exec`, that is generated after the fuzzing run. It contains a binary representation of the gathered coverage
482data in the JaCoCo format.
483
484The JaCoCo `report` command can be used to generate reports based on this coverage dump. The JaCoCo CLI tools are
485available on their [GitHub release page](https://github.com/jacoco/jacoco/releases) as `zip` file. The report tool is
486located in the `lib` folder and can be used as described in the JaCoCo
487[CLI documentation](https://www.eclemma.org/jacoco/trunk/doc/cli.html). For example the following command generates an
488HTML report in the folder `report` containing all classes available in `classes.jar` and their coverage as captured in
489the export `coverage.exec`. Source code to include in the report is searched for in `some/path/to/sources`.
490After execution the `index.html` file in the output folder can be opened in a browser.
491```shell
492java -jar path/to/jacococli.jar report coverage.exec \
493  --classfiles classes.jar \
494  --sourcefiles some/path/to/sources \
495  --html report \
496  --name FuzzCoverageReport
497```
498
499## Advanced fuzz targets
500
501### Fuzzing with Native Libraries
502
503Jazzer supports fuzzing of native libraries loaded by the JVM, for example via `System.load()`. For the fuzzer to get
504coverage feedback, these libraries have to be compiled with `-fsanitize=fuzzer-no-link`.
505
506Additional sanitizers such as AddressSanitizer or UndefinedBehaviorSanitizer are often desirable to uncover bugs inside
507the native libraries. The required compilation flags for native libraries are as follows:
508 - *AddressSanitizer*: `-fsanitize=fuzzer-no-link,address`
509 - *UndefinedBehaviorSanitizer*: `-fsanitize=fuzzer-no-link,undefined` (add `-fno-sanitize-recover=all` to crash on UBSan reports)
510
511Then, use the appropriate driver `//:jazzer_asan` or `//:jazzer_ubsan`.
512
513**Note:** Sanitizers other than AddressSanitizer and UndefinedBehaviorSanitizer are not yet supported.
514Furthermore, due to the nature of the JVM's GC, LeakSanitizer reports too many false positives to be useful and is thus disabled.
515
516The fuzz targets `ExampleFuzzerWithNativeASan` and `ExampleFuzzerWithNativeUBSan` in the `examples/` directory contain
517minimal working examples for fuzzing with native libraries. Also see `TurboJpegFuzzer` for a real-world example.
518
519### Fuzzing with Custom Mutators
520
521LibFuzzer API offers two functions to customize the mutation strategy which is especially useful when fuzzing functions
522that require structured input. Jazzer does not define `LLVMFuzzerCustomMutator` nor `LLVMFuzzerCustomCrossOver` and
523leaves the mutation strategy entirely to libFuzzer. However, custom mutators can easily be integrated by
524compiling a mutator library which defines `LLVMFuzzerCustomMutator` (and optionally `LLVMFuzzerCustomCrossOver`) and
525pre-loading the mutator library:
526
527```bash
528# Using Bazel:
529LD_PRELOAD=libcustom_mutator.so bazel run //:jazzer -- <arguments>
530# Using the binary release:
531LD_PRELOAD=libcustom_mutator.so ./jazzer <arguments>
532```
533
534## Credit
535
536The following developers have contributed to Jazzer before its public release:
537
538[Sergej Dechand](https://github.com/serj),
539[Christian Hartlage](https://github.com/dende),
540[Fabian Meumertzheim](https://github.com/fmeum),
541[Sebastian Pöplau](https://github.com/sebastianpoeplau),
542[Mohammed Qasem](https://github.com/mohqas),
543[Simon Resch](https://github.com/simonresch),
544[Henrik Schnor](https://github.com/henrikschnor),
545[Khaled Yakdan](https://github.com/kyakdan)
546
547The LLVM-style edge coverage instrumentation for JVM bytecode used by Jazzer relies on [JaCoCo](https://github.com/jacoco/jacoco).
548Previously, Jazzer used AFL-style coverage instrumentation as pioneered by [kelinci](https://github.com/isstac/kelinci).
549
550<p align="center">
551<a href="https://www.code-intelligence.com"><img src="https://www.code-intelligence.com/hubfs/Logos/CI%20Logos/CI_Header_GitHub_quer.jpeg" height=50px alt="Code Intelligence logo"></a>
552</p>
553