Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class LibFuzzerMutate {
public static final String MOCK_SIZE_KEY = "libfuzzermutator.mock.newsize";

public static byte[] mutateDefault(byte[] data, int maxSizeIncrease) {
require(maxSizeIncrease >= 0);
byte[] mutatedBytes;
if (maxSizeIncrease == 0) {
mutatedBytes = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public byte[] read(DataInputStream in) throws IOException {

@Override
public byte[] readExclusive(InputStream in) throws IOException {
return readAllBytes(in);
return enforceLength(readAllBytes(in));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.code_intelligence.jazzer.mutation.support.TestSupport.MockPseudoRandom;
import com.code_intelligence.jazzer.mutation.support.TypeHolder;
import com.google.protobuf.ByteString;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.SplittableRandom;
Expand Down Expand Up @@ -211,6 +213,19 @@ void testMinLengthMutate() {
assertThat(s).isEqualTo("gqrff\0\0\0\0\0");
}

@Test
void testReadInputsLongerThanMaxLength() throws IOException {
SerializingMutator<String> mutator =
(SerializingMutator<String>)
factory.createOrThrow(
new TypeHolder<@NotNull @WithUtf8Length(max = 5) String>() {}.annotatedType());
assertThat(mutator.toString()).isEqualTo("String");

ByteArrayInputStream in = new java.io.ByteArrayInputStream("foobarbazf".getBytes());
String s = mutator.readExclusive(in);
assertThat(s).isEqualTo("fooba");
}

@Test
void testMaxLengthMutate() {
SerializingMutator<String> mutator =
Expand Down