Skip to content

Commit b6c967c

Browse files
committed
mutator: Remove invalid inputs check
The check generates a warning for essentially all our tests and doesn't seem to be easy to make more precise.
1 parent 52e1a52 commit b6c967c

File tree

8 files changed

+4
-157
lines changed

8 files changed

+4
-157
lines changed

examples/junit/src/test/java/com/example/MutatorFuzzTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.example;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20-
import static org.junit.jupiter.api.Assertions.assertTrue;
2120

2221
import com.code_intelligence.jazzer.driver.FuzzTargetRunner;
2322
import com.code_intelligence.jazzer.junit.FuzzTest;
@@ -39,7 +38,6 @@ static void assertFuzzTargetRunner() {
3938
// FuzzTargetRunner values are not set in JUnit engine tests.
4039
String jazzerFuzz = System.getenv("JAZZER_FUZZ");
4140
if (jazzerFuzz != null && !jazzerFuzz.isEmpty()) {
42-
assertTrue(FuzzTargetRunner.invalidCorpusFilesPresent());
4341
assertEquals(FuzzTargetRunner.mutatorDebugString(), "Arguments[Nullable<List<String>>]");
4442
}
4543
}

src/main/java/com/code_intelligence/jazzer/driver/FuzzTargetRunner.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ public final class FuzzTargetRunner {
9999
private static final int LIBFUZZER_CONTINUE = 0;
100100
private static final int LIBFUZZER_RETURN_FROM_DRIVER = -2;
101101

102-
private static boolean invalidCorpusFileWarningShown = false;
103-
104102
// Keep these options used in runOne (and thus the critical path) in static final fields so that
105103
// they can be constant-folded by the JIT.
106104
private static final Set<Long> ignoredTokens =
@@ -206,18 +204,7 @@ private static int runOne(long dataPtr, int dataLength) {
206204
// call to our custom mutator and skip the read entirely.
207205
// 2. Implement a InputStream backed by Unsafe to avoid the copyToArray overhead.
208206
byte[] buf = copyToArray(dataPtr, dataLength);
209-
boolean readExactly = mutator.read(new ByteArrayInputStream(buf));
210-
211-
// All inputs constructed by the mutator framework can be read exactly, existing corpus files
212-
// may not be valid for the current fuzz target anymore, though. In this case, print a warning
213-
// once.
214-
if (!(invalidCorpusFileWarningShown || readExactly || isFixedLibFuzzerInput(buf))) {
215-
invalidCorpusFileWarningShown = true;
216-
Log.warn(
217-
"Some files in the seed corpus do not match the fuzz target signature. This indicates"
218-
+ " that they were generated with a different signature and may cause issues"
219-
+ " reproducing previous findings.");
220-
}
207+
mutator.read(new ByteArrayInputStream(buf));
221208
data = null;
222209
argument = null;
223210
} else if (useFuzzedDataProvider) {
@@ -361,13 +348,6 @@ private static int runOne(long dataPtr, int dataLength) {
361348
return LIBFUZZER_CONTINUE;
362349
}
363350

364-
private static boolean isFixedLibFuzzerInput(byte[] input) {
365-
// Detect special libFuzzer inputs which can not be processed by the mutator framework.
366-
// libFuzzer always uses an empty input, and one with a single line feed (10) to indicate
367-
// end of initial corpus file processing.
368-
return input.length == 0 || (input.length == 1 && input[0] == 10);
369-
}
370-
371351
// Called via JNI, being passed data from LLVMFuzzerCustomMutator.
372352
@SuppressWarnings("unused")
373353
private static int mutateOne(long data, int size, int maxSize, int seed) {
@@ -585,14 +565,6 @@ public static String mutatorDebugString() {
585565
return mutator != null ? mutator.toString() : null;
586566
}
587567

588-
/**
589-
* Returns whether the current mutator has detected invalid corpus files. If no mutator is used,
590-
* returns false.
591-
*/
592-
public static boolean invalidCorpusFilesPresent() {
593-
return mutator != null && invalidCorpusFileWarningShown;
594-
}
595-
596568
/**
597569
* Disables libFuzzer's fuzz target exit detection until the next call to {@link #runOne}.
598570
*

src/main/java/com/code_intelligence/jazzer/junit/SeedArgumentsProvider.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext extensionCo
8484
+ "To start fuzzing, run a test with the environment variable JAZZER_FUZZ"
8585
+ " set to a non-empty value.");
8686
}
87-
if (!serializer.allReadsValid()) {
88-
extensionContext.publishReportEntry(
89-
"Some files in the seed corpus do not match the fuzz target signature.\n"
90-
+ "This indicates that they were generated with a different signature and"
91-
+ " may cause issues reproducing previous findings.");
92-
}
9387
});
9488
}
9589

src/main/java/com/code_intelligence/jazzer/junit/SeedSerializer.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
interface SeedSerializer {
3030
Object[] read(byte[] bytes);
3131

32-
default boolean allReadsValid() {
33-
return true;
34-
}
35-
3632
// Implementations can assume that the argument array contains valid arguments for the method that
3733
// this instance has been constructed for.
3834
byte[] write(Object[] args) throws UnsupportedOperationException;
@@ -95,23 +91,17 @@ public byte[] write(Object[] args) throws UnsupportedOperationException {
9591

9692
final class ArgumentsMutatorSeedSerializer implements SeedSerializer {
9793
private final ArgumentsMutator mutator;
98-
private boolean allReadsValid;
9994

10095
public ArgumentsMutatorSeedSerializer(ArgumentsMutator mutator) {
10196
this.mutator = mutator;
10297
}
10398

10499
@Override
105100
public Object[] read(byte[] bytes) {
106-
allReadsValid &= mutator.read(new ByteArrayInputStream(bytes));
101+
mutator.read(new ByteArrayInputStream(bytes));
107102
return mutator.getArguments();
108103
}
109104

110-
@Override
111-
public boolean allReadsValid() {
112-
return allReadsValid;
113-
}
114-
115105
@Override
116106
public byte[] write(Object[] args) {
117107
ByteArrayOutputStream out = new ByteArrayOutputStream();

src/main/java/com/code_intelligence/jazzer/mutation/ArgumentsMutator.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.code_intelligence.jazzer.mutation;
1818

1919
import static com.code_intelligence.jazzer.mutation.mutator.Mutators.validateAnnotationUsage;
20-
import static com.code_intelligence.jazzer.mutation.support.InputStreamSupport.extendWithReadExactly;
2120
import static com.code_intelligence.jazzer.mutation.support.Preconditions.require;
2221
import static com.code_intelligence.jazzer.mutation.support.StreamSupport.toArrayOrEmpty;
2322
import static java.lang.String.format;
@@ -31,7 +30,6 @@
3130
import com.code_intelligence.jazzer.mutation.combinator.ProductMutator;
3231
import com.code_intelligence.jazzer.mutation.engine.SeededPseudoRandom;
3332
import com.code_intelligence.jazzer.mutation.mutator.Mutators;
34-
import com.code_intelligence.jazzer.mutation.support.InputStreamSupport.ReadExactlyInputStream;
3533
import com.code_intelligence.jazzer.mutation.support.Preconditions;
3634
import java.io.ByteArrayInputStream;
3735
import java.io.IOException;
@@ -116,15 +114,12 @@ public void crossOver(InputStream data1, InputStream data2, long seed) {
116114
}
117115

118116
/**
119-
* @return if the given input stream was consumed exactly
120117
* @throws UncheckedIOException if the underlying InputStream throws
121118
*/
122-
public boolean read(ByteArrayInputStream data) {
119+
public void read(ByteArrayInputStream data) {
123120
try {
124-
ReadExactlyInputStream is = extendWithReadExactly(data);
125-
arguments = productMutator.readExclusive(is);
121+
arguments = productMutator.readExclusive(data);
126122
argumentsExposed = false;
127-
return is.isConsumedExactly();
128123
} catch (IOException e) {
129124
throw new UncheckedIOException(e);
130125
}

src/main/java/com/code_intelligence/jazzer/mutation/support/InputStreamSupport.java

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -193,64 +193,5 @@ public void close() throws IOException {
193193
}
194194
}
195195

196-
/**
197-
* Wraps a given stream with the functionality to detect if it was read exactly. To do so, the
198-
* stream must provide an accurate implementation of {@link InputStream#available()}, hence it's
199-
* restricted to {@link ByteArrayInputStream} for now.
200-
*
201-
* @return {@code stream} extended that detects if it was consumed exactly
202-
*/
203-
public static ReadExactlyInputStream extendWithReadExactly(ByteArrayInputStream stream) {
204-
return new ReadExactlyInputStream(requireNonNull(stream));
205-
}
206-
207-
public static final class ReadExactlyInputStream extends InputStream {
208-
private final InputStream stream;
209-
private boolean eof;
210-
211-
private ReadExactlyInputStream(InputStream stream) {
212-
this.stream = stream;
213-
this.eof = false;
214-
}
215-
216-
public boolean isConsumedExactly() {
217-
try {
218-
// Forwards availability check to the underlying ByteInputStream,
219-
// which is accurate for the number of available bytes.
220-
return !eof && available() == 0;
221-
} catch (IOException e) {
222-
return false;
223-
}
224-
}
225-
226-
@Override
227-
public int read() throws IOException {
228-
int res = stream.read();
229-
if (res == -1) {
230-
eof = true;
231-
}
232-
return res;
233-
}
234-
235-
@Override
236-
public int read(byte[] b, int off, int len) throws IOException {
237-
int read = stream.read(b, off, len);
238-
if (read < len) {
239-
eof = true;
240-
}
241-
return read;
242-
}
243-
244-
@Override
245-
public int available() throws IOException {
246-
return stream.available();
247-
}
248-
249-
@Override
250-
public void close() throws IOException {
251-
stream.close();
252-
}
253-
}
254-
255196
private InputStreamSupport() {}
256197
}

src/test/java/com/code_intelligence/jazzer/junit/MutatorTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@
3535
import java.nio.file.Files;
3636
import java.nio.file.Path;
3737
import java.nio.file.Paths;
38-
import org.assertj.core.api.Condition;
3938
import org.junit.Before;
4039
import org.junit.Rule;
4140
import org.junit.Test;
42-
import org.junit.platform.engine.reporting.ReportEntry;
4341
import org.junit.platform.testkit.engine.EngineExecutionResults;
4442
import org.junit.platform.testkit.engine.EngineTestKit;
45-
import org.junit.platform.testkit.engine.Event;
4643
import org.junit.rules.TemporaryFolder;
4744

4845
public class MutatorTest {
@@ -97,15 +94,6 @@ public void fuzzingEnabled() {
9794
event(type(STARTED), container(ENGINE)),
9895
event(type(STARTED), container(uniqueIdSubstrings(ENGINE, CLAZZ))),
9996
event(type(STARTED), container(uniqueIdSubstrings(ENGINE, CLAZZ, LIFECYCLE_FUZZ))),
100-
// Invalid corpus input warning
101-
event(
102-
type(REPORTING_ENTRY_PUBLISHED),
103-
container(uniqueIdSubstrings(ENGINE, CLAZZ, LIFECYCLE_FUZZ)),
104-
new Condition<>(
105-
Event.byPayload(
106-
ReportEntry.class,
107-
(it) -> it.getKeyValuePairs().values().contains(INVALID_SIGNATURE_ENTRY)),
108-
"has invalid signature entry reporting entry")),
10997
event(
11098
type(FINISHED),
11199
container(uniqueIdSubstrings(ENGINE, CLAZZ, LIFECYCLE_FUZZ)),
@@ -170,10 +158,6 @@ public void fuzzingDisabled() {
170158
event(type(STARTED), container(uniqueIdSubstrings(ENGINE, CLAZZ))),
171159
event(type(STARTED), container(uniqueIdSubstrings(ENGINE, CLAZZ, LIFECYCLE_FUZZ))),
172160
// Deactivated fuzzing warning
173-
event(
174-
type(REPORTING_ENTRY_PUBLISHED),
175-
container(uniqueIdSubstrings(ENGINE, CLAZZ, LIFECYCLE_FUZZ))),
176-
// Invalid corpus input warning
177161
event(
178162
type(REPORTING_ENTRY_PUBLISHED),
179163
container(uniqueIdSubstrings(ENGINE, CLAZZ, LIFECYCLE_FUZZ))),

src/test/java/com/code_intelligence/jazzer/mutation/support/InputStreamSupportTest.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
package com.code_intelligence.jazzer.mutation.support;
1818

1919
import static com.code_intelligence.jazzer.mutation.support.InputStreamSupport.cap;
20-
import static com.code_intelligence.jazzer.mutation.support.InputStreamSupport.extendWithReadExactly;
2120
import static com.code_intelligence.jazzer.mutation.support.InputStreamSupport.extendWithZeros;
2221
import static com.code_intelligence.jazzer.mutation.support.InputStreamSupport.infiniteZeros;
2322
import static com.code_intelligence.jazzer.mutation.support.InputStreamSupport.readAllBytes;
2423
import static com.google.common.truth.Truth.assertThat;
2524

26-
import com.code_intelligence.jazzer.mutation.support.InputStreamSupport.ReadExactlyInputStream;
2725
import java.io.ByteArrayInputStream;
2826
import java.io.IOException;
2927
import java.io.InputStream;
@@ -118,29 +116,4 @@ void testReadAllBytes(int length) throws IOException {
118116

119117
assertThat(readAllBytes(input)).isEqualTo(bytes);
120118
}
121-
122-
@Test
123-
@SuppressWarnings("ResultOfMethodCallIgnored")
124-
void testReadExactly() throws IOException {
125-
ReadExactlyInputStream ce = extendWithReadExactly(new ByteArrayInputStream(new byte[] {0, 1}));
126-
assertThat(ce.isConsumedExactly()).isFalse();
127-
ce.read();
128-
assertThat(ce.isConsumedExactly()).isFalse();
129-
ce.read();
130-
assertThat(ce.isConsumedExactly()).isTrue();
131-
ce.read();
132-
assertThat(ce.isConsumedExactly()).isFalse();
133-
}
134-
135-
@Test
136-
@SuppressWarnings("ResultOfMethodCallIgnored")
137-
void testReadExactly_readBytes() throws IOException {
138-
ReadExactlyInputStream ce =
139-
extendWithReadExactly(new ByteArrayInputStream(new byte[] {0, 1, 2}));
140-
assertThat(ce.isConsumedExactly()).isFalse();
141-
ce.read(new byte[3]);
142-
assertThat(ce.isConsumedExactly()).isTrue();
143-
ce.read(new byte[1]);
144-
assertThat(ce.isConsumedExactly()).isFalse();
145-
}
146119
}

0 commit comments

Comments
 (0)