Class Jazzer
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault number of counters allocated for each call site of a method that requires registering a range of artificial coverage counters, e.g., Jazzer maximize API.static final intA 32-bit random number that hooks can use to make pseudo-random choices between multiple possible mutations they could guide the fuzzer towards. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexploreState(byte state) Convenience overload ofexploreState(byte, int)that allows using automatically generated call-site identifiers.static voidexploreState(byte state, int id) Instructs the fuzzer to attain as many possible values forstateas possible.static voidguideTowardsContainment(String haystack, String needle, int id) Instructs the fuzzer to guide its mutations towards makinghaystackcontainneedleas a substring.static voidguideTowardsEquality(byte[] current, byte[] target, int id) Instructs the fuzzer to guide its mutations towards makingcurrentequal totarget.static voidguideTowardsEquality(String current, String target, int id) Instructs the fuzzer to guide its mutations towards makingcurrentequal totarget.static voidmaximize(long value, long minValue, long maxValue) Convenience overload ofmaximize(long, long, long, int, int)that usesDEFAULT_NUM_COUNTERScounters and an automatically generated call-site id.static voidmaximize(long value, long minValue, long maxValue, int numCounters) Convenience overload ofmaximize(long, long, long, int, int)that uses a custom number of counters and an automatically generated call-site id.static voidmaximize(long value, long minValue, long maxValue, int numCounters, int id) Core implementation of the hill-climbing maximize API.static voidminimize(long value, long minValue, long maxValue) Convenience overload ofminimize(long, long, long, int, int)that usesDEFAULT_NUM_COUNTERScounters and an automatically generated call-site id.static voidminimize(long value, long minValue, long maxValue, int numCounters) Convenience overload ofminimize(long, long, long, int, int)that uses a custom number of counters and an automatically generated call-site id.static voidminimize(long value, long minValue, long maxValue, int numCounters, int id) Core implementation of the hill-climbing minimize API.static voidonFuzzTargetReady(Runnable callback) Register a callback to be executed right before the fuzz target is executed for the first time.static voidreportFindingFromHook(Throwable finding) Make Jazzer report the providedThrowableas a finding.
-
Field Details
-
DEFAULT_NUM_COUNTERS
public static final int DEFAULT_NUM_COUNTERSDefault number of counters allocated for each call site of a method that requires registering a range of artificial coverage counters, e.g., Jazzer maximize API. The user's value range is linearly mapped onto this many counters.- See Also:
-
SEED
public static final int SEEDA 32-bit random number that hooks can use to make pseudo-random choices between multiple possible mutations they could guide the fuzzer towards. Hooks must not base the decision whether to report a finding on this number as this will make findings non-reproducible.This is the same number that libFuzzer uses as a seed internally, which makes it possible to deterministically reproduce a previous fuzzing run by supplying the seed value printed by libFuzzer as the value of the
-seed.
-
-
Method Details
-
guideTowardsEquality
Instructs the fuzzer to guide its mutations towards makingcurrentequal totarget.If the relation between the raw fuzzer input and the value of
currentis relatively complex, running the fuzzer with the argument-use_value_profile=1may be necessary to achieve equality.- Parameters:
current- a non-constant string observed during fuzz target executiontarget- a string thatcurrentshould become equal to, but currently isn'tid- a (probabilistically) unique identifier for this particular compare hint
-
guideTowardsEquality
public static void guideTowardsEquality(byte[] current, byte[] target, int id) Instructs the fuzzer to guide its mutations towards makingcurrentequal totarget.If the relation between the raw fuzzer input and the value of
currentis relatively complex, running the fuzzer with the argument-use_value_profile=1may be necessary to achieve equality.- Parameters:
current- a non-constant byte array observed during fuzz target executiontarget- a byte array thatcurrentshould become equal to, but currently isn'tid- a (probabilistically) unique identifier for this particular compare hint
-
guideTowardsContainment
Instructs the fuzzer to guide its mutations towards makinghaystackcontainneedleas a substring.If the relation between the raw fuzzer input and the value of
haystackis relatively complex, running the fuzzer with the argument-use_value_profile=1may be necessary to satisfy the substring check.- Parameters:
haystack- a non-constant string observed during fuzz target executionneedle- a string that should be contained inhaystackas a substring, but currently isn'tid- a (probabilistically) unique identifier for this particular compare hint
-
exploreState
public static void exploreState(byte state, int id) Instructs the fuzzer to attain as many possible values forstateas possible.Call this function from a fuzz target or a hook to help the fuzzer track partial progress (e.g. by passing the length of a common prefix of two lists that should become equal) or explore different values of state that is not directly related to code coverage (see the MazeFuzzer example).
Each unique state value is tracked via libFuzzer's counter bucketing mechanism, enabling us to represent 8 different states for each coverage counter. As a result, all 256 byte values are distinguished by mapping each to a unique (counter, bucket) pair across 32 counters. See: https://github.com/llvm/llvm-project/blob/972e73b812cb7b6dd349c7c07daae73314f29e8f/compiler-rt/lib/fuzzer/FuzzerTracePC.h#L213-L235
- Parameters:
state- a numeric encoding of a state that should be varied by the fuzzerid- a (probabilistically) unique identifier for this particular state hint
-
exploreState
public static void exploreState(byte state) Convenience overload ofexploreState(byte, int)that allows using automatically generated call-site identifiers. During instrumentation, calls to this method are replaced with calls toexploreState(byte, int)using a unique id for each call site.Without instrumentation, this is a no-op.
- Parameters:
state- a numeric encoding of a state that should be varied by the fuzzer- See Also:
-
maximize
public static void maximize(long value, long minValue, long maxValue, int numCounters, int id) Core implementation of the hill-climbing maximize API. It mapsvaluefrom the range [minValue,maxValue] ontonumCounterscoverage counters via linear interpolation, then sets all counters from 0 to the mapped offset.Values below
minValueproduce no signal. Values abovemaxValueare clamped.Must be invoked with the same
minValue,maxValue, andnumCountersfor a givenidacross all calls. Passing different values is illegal.- Parameters:
value- the value to maximizeminValue- the minimum expected value (inclusive)maxValue- the maximum expected value (inclusive); must be >=minValuenumCounters- the number of counters to allocate; must be > 0id- a unique identifier for this call site (must be consistent across runs)- Throws:
JazzerApiException- ifmaxValue < minValueornumCounters <= 0
-
maximize
public static void maximize(long value, long minValue, long maxValue) Convenience overload ofmaximize(long, long, long, int, int)that usesDEFAULT_NUM_COUNTERScounters and an automatically generated call-site id.During instrumentation, calls to this method are replaced by a hook that supplies a unique id for each call site. Without instrumentation, this is a no-op.
// Maximize temperature in [0, 4500] Jazzer.maximize(temperature, 0, 4500);- Parameters:
value- the value to maximizeminValue- the minimum expected value (inclusive)maxValue- the maximum expected value (inclusive)- See Also:
-
maximize
public static void maximize(long value, long minValue, long maxValue, int numCounters) Convenience overload ofmaximize(long, long, long, int, int)that uses a custom number of counters and an automatically generated call-site id.During instrumentation, calls to this method are replaced by a hook that supplies a unique id for each call site. Without instrumentation, this is a no-op.
- Parameters:
value- the value to maximizeminValue- the minimum expected value (inclusive)maxValue- the maximum expected value (inclusive)numCounters- the number of counters to allocate; must be > 0- See Also:
-
minimize
public static void minimize(long value, long minValue, long maxValue, int numCounters, int id) Core implementation of the hill-climbing minimize API. It mapsvaluefrom the range [minValue,maxValue] ontonumCounterscoverage counters via inverse linear interpolation, then sets all counters from 0 to the mapped offset.Lower values produce more signal (more counters set), which causes the fuzzer to prefer inputs that result in lower values. Values above
maxValueproduce no signal. Values belowminValueare clamped.Must be invoked with the same
minValue,maxValue, andnumCountersfor a givenidacross all calls. Passing different values is illegal.- Parameters:
value- the value to minimizeminValue- the minimum expected value (inclusive)maxValue- the maximum expected value (inclusive); must be >=minValuenumCounters- the number of counters to allocate; must be > 0id- a unique identifier for this call site (must be consistent across runs)- Throws:
JazzerApiException- ifmaxValue < minValueornumCounters <= 0
-
minimize
public static void minimize(long value, long minValue, long maxValue) Convenience overload ofminimize(long, long, long, int, int)that usesDEFAULT_NUM_COUNTERScounters and an automatically generated call-site id.During instrumentation, calls to this method are replaced by a hook that supplies a unique id for each call site. Without instrumentation, this is a no-op.
// Minimize temperature in [0, 4000] Jazzer.minimize(temperature, 0, 4000);- Parameters:
value- the value to minimizeminValue- the minimum expected value (inclusive)maxValue- the maximum expected value (inclusive)- See Also:
-
minimize
public static void minimize(long value, long minValue, long maxValue, int numCounters) Convenience overload ofminimize(long, long, long, int, int)that uses a custom number of counters and an automatically generated call-site id.During instrumentation, calls to this method are replaced by a hook that supplies a unique id for each call site. Without instrumentation, this is a no-op.
- Parameters:
value- the value to minimizeminValue- the minimum expected value (inclusive)maxValue- the maximum expected value (inclusive)numCounters- the number of counters to allocate; must be > 0- See Also:
-
reportFindingFromHook
Make Jazzer report the providedThrowableas a finding.Note: This method must only be called from a method hook. In a fuzz target, simply throw an exception to trigger a finding.
- Parameters:
finding- the finding that Jazzer should report
-
onFuzzTargetReady
Register a callback to be executed right before the fuzz target is executed for the first time.This can be used to disable hooks until after Jazzer has been fully initializing, e.g. to prevent Jazzer internals from triggering hooks on Java standard library classes.
- Parameters:
callback- the callback to execute
-