Skip to content

Commit d4cd518

Browse files
committed
-
1 parent 0216f92 commit d4cd518

2 files changed

Lines changed: 25 additions & 44 deletions

File tree

src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,68 @@
1717
package org.xerial.snappy.fuzz;
1818

1919
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
20-
2120
import org.xerial.snappy.Snappy;
2221
import org.xerial.snappy.BitShuffle;
2322
import java.io.IOException;
2423
import java.util.Arrays;
2524

26-
2725
public class BitShuffleFuzzer {
26+
private static final int SIZE = 4096;
27+
2828
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
29-
int SIZE = 4096;
30-
fuzz_bitshuffle_ints(data.consumeInts(SIZE));
31-
fuzz_bitshuffle_longs(data.consumeLongs(SIZE));
32-
fuzz_bitshuffle_shorts(data.consumeShorts(SIZE));
29+
fuzzBitshuffleInts(data.consumeInts(SIZE));
30+
fuzzBitshuffleLongs(data.consumeLongs(SIZE));
31+
fuzzBitshuffleShorts(data.consumeShorts(SIZE));
3332
}
3433

35-
static void fuzzBitshuffleInts(int[] original){
34+
static void fuzzBitshuffleInts(int[] original) {
3635
int[] result;
3736

38-
try{
37+
try {
3938
byte[] shuffledByteArray = BitShuffle.shuffle(original);
4039
byte[] compressed = Snappy.compress(shuffledByteArray);
4140
byte[] uncompressed = Snappy.uncompress(compressed);
4241
result = BitShuffle.unshuffleIntArray(uncompressed);
43-
}
44-
catch( IOException e ){
42+
} catch (IOException e) {
4543
throw new RuntimeException(e);
4644
}
47-
48-
if(Arrays.equals(original,result) == false)
49-
{
45+
46+
if (!Arrays.equals(original, result)) {
5047
throw new IllegalStateException("Original and uncompressed data are different");
5148
}
49+
}
5250

53-
}//fuzz_bitshuffle_ints
54-
55-
static void fuzz_bitshuffle_longs(long[] original){
51+
static void fuzzBitshuffleLongs(long[] original) {
5652
long[] result;
5753

58-
try{
54+
try {
5955
byte[] shuffledByteArray = BitShuffle.shuffle(original);
6056
byte[] compressed = Snappy.compress(shuffledByteArray);
6157
byte[] uncompressed = Snappy.uncompress(compressed);
6258
result = BitShuffle.unshuffleLongArray(uncompressed);
63-
}
64-
catch( IOException e ){
59+
} catch (IOException e) {
6560
throw new RuntimeException(e);
6661
}
67-
68-
if(Arrays.equals(original,result) == false)
69-
{
62+
63+
if (!Arrays.equals(original, result)) {
7064
throw new IllegalStateException("Original and uncompressed data are different");
7165
}
66+
}
7267

73-
}//fuzz_bitshuffle_longs
74-
75-
static void fuzz_bitshuffle_shorts(short[] original){
68+
static void fuzzBitshuffleShorts(short[] original) {
7669
short[] result;
7770

78-
try{
71+
try {
7972
byte[] shuffledByteArray = BitShuffle.shuffle(original);
8073
byte[] compressed = Snappy.compress(shuffledByteArray);
8174
byte[] uncompressed = Snappy.uncompress(compressed);
8275
result = BitShuffle.unshuffleShortArray(uncompressed);
83-
}
84-
catch( IOException e ){
76+
} catch (IOException e) {
8577
throw new RuntimeException(e);
8678
}
87-
88-
if(Arrays.equals(original,result) == false)
89-
{
79+
80+
if (!Arrays.equals(original, result)) {
9081
throw new IllegalStateException("Original and uncompressed data are different");
9182
}
92-
93-
}//fuzz_bitshuffle_shorts
94-
83+
}
9584
}
96-

src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717
package org.xerial.snappy.fuzz;
1818

1919
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
20-
21-
import org.xerial.snappy.Snappy;
2220
import org.xerial.snappy.SnappyInputStream;
2321
import org.xerial.snappy.SnappyOutputStream;
24-
import org.xerial.snappy.SnappyCodec;
2522
import java.io.IOException;
2623
import java.io.ByteArrayInputStream;
2724
import java.io.ByteArrayOutputStream;
28-
import java.io.BufferedInputStream;
2925
import java.util.Arrays;
3026

3127
public class SnappyStreamFuzzer {
@@ -51,14 +47,11 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) {
5147
out.flush();
5248
uncompressed = out.toByteArray();
5349
}
54-
}
55-
catch (IOException e)
56-
{
50+
} catch (IOException e) {
5751
throw new RuntimeException(e);
5852
}
5953

60-
if(Arrays.equals(original,uncompressed) == false)
61-
{
54+
if (!Arrays.equals(original, uncompressed)) {
6255
throw new IllegalStateException("Original and uncompressed data are different");
6356
}
6457
}

0 commit comments

Comments
 (0)