You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> These settings apply to the old fuzzing approach using a `fuzzerTestOneInput` method and the native Jazzer binary. They don't work in the new JUnit integration.
1
+
# Advanced options
15
2
16
3
## Using Jazzer Standalone
17
4
There are two ways to use Jazzer standalone: by using the `jazzer` binary or by calling the Jazzer main class directly.
@@ -39,7 +26,44 @@ Please refer to [libFuzzer](https://llvm.org/docs/LibFuzzer.html) for documentat
39
26
Various command line options are available to control the instrumentation and fuzzer execution.
40
27
A full list of command-line flags can be printed with the `--help` flag.
41
28
42
-
### Passing JVM Arguments
29
+
30
+
## Reproducing a finding
31
+
32
+
When Jazzer manages to find an input that causes an uncaught exception or a failed assertion, it prints a Java stack trace and creates two files that aid in reproducing the crash without Jazzer:
33
+
34
+
*`crash-<sha1_of_input>` contains the raw bytes passed to the fuzz target (just as with libFuzzer C/C++ fuzz targets).
35
+
The crash can be reproduced with Jazzer by passing the path to the crash file as the only positional argument.
36
+
*`Crash-<sha1_of_input>.java` contains a class with a `main` function that invokes the fuzz target with the crashing input.
37
+
This is especially useful if using `FuzzedDataProvider` as the raw bytes of the input do not directly correspond to the values consumed by the fuzz target.
38
+
The `.java` file can be compiled with just the fuzz target and its dependencies in the classpath (plus `jazzer_standalone.jar` or `com.code-intelligence:jazzer-api:<version>` if using `FuzzedDataProvider`).
39
+
40
+
## Minimizing a crashing input
41
+
42
+
With the following argument you can minimize a crashing input to find the smallest input that reproduces the same "bug":
43
+
44
+
```bash
45
+
-minimize_crash=1 <path/to/crashing_input>
46
+
```
47
+
48
+
## Parallel execution
49
+
50
+
libFuzzer offers the `-fork=N` and `-jobs=N` flags for parallel fuzzing, both of which are also supported by Jazzer.
51
+
52
+
53
+
## Recommended JVM Options
54
+
55
+
The following JVM settings are recommended for running Jazzer:
56
+
57
+
*`-XX:-OmitStackTraceInFastThrow`: Ensures that stack traces are emitted even on hot code paths.
58
+
This may hurt performance if your Fuzz Test frequently throws and catches exceptions, but also helps find flaky bugs.
59
+
*`-XX:+UseParallelGC`: Optimizes garbage collection for high throughput rather than low latency.
60
+
*`-XX:+CriticalJNINatives`: Is supported with JDK 17 and earlier and improves the runtime performance of Jazzer's
61
+
instrumentation.
62
+
*`-XX:+EnableDynamicAgentLoading`: Silences a warning with JDK 21 and later triggered by the Java agent that Jazzer
63
+
attaches to instrument the fuzzed code.
64
+
65
+
66
+
## Passing JVM Arguments
43
67
44
68
When Jazzer is started using the `jazzer` binary, it starts a JVM in which it executes the fuzz target.
45
69
Arguments for this JVM can be provided via the `JAVA_OPTS` environment variable.
@@ -73,7 +97,7 @@ Both flags take a list of glob patterns for the java class name separated by col
73
97
By default, JVM-internal classes and Java as well as Kotlin standard library classes are not instrumented,
74
98
so these do not need to be excluded manually.
75
99
76
-
###Trace Instrumentation
100
+
## Trace Instrumentation
77
101
78
102
The agent adds additional hooks for tracing compares, integer divisions, switch statements and array indices.
79
103
These hooks correspond to [clang's data flow hooks](https://clang.llvm.org/docs/SanitizerCoverage.html#tracing-data-flow).
@@ -88,35 +112,22 @@ The particular instrumentation types to apply can be specified using the `--trac
88
112
89
113
Multiple instrumentation types can be combined with a colon (Linux, macOS) or a semicolon (Windows).
90
114
91
-
###Value Profile
115
+
## Value Profile
92
116
93
117
The run-time flag `-use_value_profile=1` enables [libFuzzer's value profiling mode](https://llvm.org/docs/LibFuzzer.html#value-profile).
94
118
When running with this flag, the feedback about compares and constants received from Jazzer's trace instrumentation is associated with the particular bytecode location and used to provide additional coverage instrumentation.
95
119
See [ExampleValueProfileFuzzer.java](../examples/src/main/java/com/example/ExampleValueProfileFuzzer.java) for a fuzz target that would be very hard to fuzz without value profile.
96
120
97
-
### Custom hooks
98
-
99
-
In order to obtain information about data passed into functions such as `String.equals` or `String.startsWith`, Jazzer hooks invocations to these methods.
100
-
This functionality is also available to fuzz targets, where it can be used to implement custom sanitizers or stub out methods that block the fuzzer from progressing (e.g. checksum verifications or random number generation).
101
-
See [ExampleFuzzerHooks.java](../examples/src/main/java/com/example/ExampleFuzzerHooks.java) for an example of such a hook.
102
-
An example for a sanitizer can be found in [ExamplePathTraversalFuzzerHooks.java](../examples/src/main/java/com/example/ExamplePathTraversalFuzzerHooks.java).
103
-
104
-
Method hooks can be declared using the `@MethodHook` annotation defined in the `com.code_intelligence.jazzer.api` package, which is contained in `jazzer_standalone.jar` (binary release) or in the Maven artifact [`com.code-intelligence:jazzer-api`](https://search.maven.org/search?q=g:com.code-intelligence%20a:jazzer-api).
105
-
See the [javadocs of the `@MethodHook` API](https://codeintelligencetesting.github.io/jazzer-docs/jazzer-api/com/code_intelligence/jazzer/api/MethodHook.html) for more details.
106
-
107
-
To use the compiled method hooks, they have to be available on the classpath provided by `--cp` and can then be loaded by providing the flag `--custom_hooks`, which takes a colon-separated list of names of classes to load hooks from.
108
-
Hooks have to be loaded from separate JAR files 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-).
109
-
The list of custom hooks can alternatively be specified via the `Jazzer-Hook-Classes` attribute in the fuzz target JAR's manifest.
110
121
111
-
###Keep Going
122
+
## Keep Going
112
123
113
124
With the flag `--keep_going=N` Jazzer continues fuzzing until `N` unique stack traces have been encountered.
114
125
Specifically `--keep-going=0` will keep the fuzzer running until another stop condition (e.g. maximum runtime) is met.
115
126
116
127
Particular stack traces can also be ignored based on their `DEDUP_TOKEN` by passing a comma-separated list of tokens via
117
128
`--ignore=<token_1>,<token2>`.
118
129
119
-
###Export Coverage Information
130
+
## Export Coverage Information
120
131
121
132
> [!WARNING]\
122
133
> This feature is deprecated. The standalone JaCoCo agent should be used to generate coverage reports.
0 commit comments