-
Notifications
You must be signed in to change notification settings - Fork 165
Maximize API #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Maximize API #1036
Changes from all commits
02b79ba
9519572
41b5381
b1523e4
f21d4ba
68ee269
93921c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright 2026 Code Intelligence GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.example; | ||
|
|
||
| import com.code_intelligence.jazzer.api.Jazzer; | ||
| import com.code_intelligence.jazzer.junit.FuzzTest; | ||
| import com.code_intelligence.jazzer.mutation.annotation.NotNull; | ||
|
|
||
| public class ReactorFuzzTest { | ||
|
|
||
| @FuzzTest | ||
| public void fuzz(@NotNull String input) { | ||
| for (char c : input.toCharArray()) { | ||
| if (c < 32 || c > 126) return; | ||
| } | ||
| controlReactor(input); | ||
| } | ||
|
|
||
| private void controlReactor(String commands) { | ||
| long temperature = 0; // Starts cold | ||
|
|
||
| for (char cmd : commands.toCharArray()) { | ||
| // Complex, chaotic feedback loop. | ||
| // It is hard to predict which character increases temperature | ||
| // because it depends on the CURRENT temperature. | ||
| if ((temperature ^ cmd) % 3 == 0) { | ||
| temperature += (cmd % 10); // Heat up slightly | ||
| } else if ((temperature ^ cmd) % 3 == 1) { | ||
| temperature -= (cmd % 8); // Cool down slightly | ||
| } else { | ||
| temperature += 1; // Tiny increase | ||
| } | ||
|
|
||
| // Prevent dropping below absolute zero for simulation sanity | ||
| if (temperature < 0) temperature = 0; | ||
| } | ||
| // THE GOAL: MAXIMIZATION | ||
| // We need to drive 'temperature' to an extreme value. | ||
| // Standard coverage is 100% constant here (it just loops). | ||
| Jazzer.maximize(temperature, 500, 4500); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an idea: From the user perspective, would it make more sense to give them an object they can initialize beforehand and then call later in their code? Something like this: static {
CoverageAmplifier reactorAmplifier = new CoverageAmplifier(2000, 3000);
}
@FuzzTest
public void test(@InRange(min=10, max=20) int data) {
coverageAmplifier.maximize(data);
// or
coverageAmplifier.minimize(data);
}This might also improve performance quite a bit, because at the moment, we call
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another idea: the current user range is a 1:1 mapping from values to the number of coverage counters. This will make sure that a casual user doesn't flood the corpus with a million inputs by accident. For example, this fuzz test gives me 60 exec/s: @FuzzTest(maxDuration = "0m")
public void decompressRoundtrip(@InRange(min=0, max=20000) int high) {
Jazzer.maximize(high, 0, 100000);
}
#454 REDUCE cov: 20002 ft: 20002 corp: 7/29b lim: 4096 exec/s: 56 rss: 5761Mb L: 4/5 MS: 2 CopyPart-Custom-
#512 pulse cov: 20002 ft: 20002 corp: 7/29b lim: 4096 exec/s: 56 rss: 5761MbMaybe the user can add the number of counters explicitly: |
||
| if (temperature >= 4500) { | ||
| throw new RuntimeException("Meltdown! Temperature maximized."); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright 2024 Code Intelligence GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.code_intelligence.jazzer.api; | ||
|
|
||
| /** | ||
| * Signals error from the Jazzer API (e.g. invalid arguments to {@link Jazzer#maximize}). | ||
| * | ||
| * <p>This exception is treated as a fatal error by the fuzzing engine rather than as a finding in | ||
| * the code under test. When thrown during fuzzing, it stops the current fuzz test with an error | ||
| * instead of reporting a bug in the fuzz target. | ||
| */ | ||
| public class JazzerApiException extends RuntimeException { | ||
| public JazzerApiException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public JazzerApiException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| public JazzerApiException(Throwable cause) { | ||
| super(cause); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two issues here:
This suggests that users can dynamically set the values
minValueandmaxValue, whereas we assume them to be constant. I think, we should enforce that by double-checking that the values remain constant each time we callJazzer.maximize()and error out if they do not.Also, the exceptions thrown in the hooked method don't stop the fuzzer:
Results in exceptions thrown, but the fuzzing process not stopped. Maybe it's because they are thrown in the hook?