Skip to content

Commit 56692d3

Browse files
committed
WIP: decode bytes as CESU8 when converting to char[]
1 parent 683af30 commit 56692d3

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/main/java/com/code_intelligence/jazzer/mutation/mutator/lang/PrimitiveArrayMutatorFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.lang.reflect.AnnotatedArrayType;
4343
import java.lang.reflect.AnnotatedType;
4444
import java.nio.ByteBuffer;
45+
import java.nio.charset.Charset;
4546
import java.util.Optional;
4647
import java.util.function.BiFunction;
4748
import java.util.function.Function;
@@ -260,11 +261,7 @@ public char[] postMutateChars(byte[] bytes, PseudoRandom prng) {
260261
if (prng.choice()) {
261262
return (char[]) toPrimitive.apply(bytes);
262263
} else {
263-
char[] chars = new char[bytes.length];
264-
for (int i = 0; i < chars.length; i++) {
265-
chars[i] = (char) bytes[i];
266-
}
267-
return chars;
264+
return new String(bytes, Charset.forName("CESU-8")).toCharArray();
268265
}
269266
}
270267

tests/src/test/java/com/example/CharArrayFuzzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public static void fuzzerTestOneInput(char[] data) {
2222
return;
2323
}
2424
String expression = new String(data);
25-
if (expression.contains("jazzer")) {
26-
throw new RuntimeException("found jazzer");
25+
if (expression.equals("中 Bös3r \uD801\uDC00 C0d3 中")) {
26+
throw new RuntimeException("Found evil code");
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)