|
17 | 17 | package org.xerial.snappy.fuzz; |
18 | 18 |
|
19 | 19 | import com.code_intelligence.jazzer.api.FuzzedDataProvider; |
20 | | - |
21 | 20 | import org.xerial.snappy.Snappy; |
22 | 21 | import org.xerial.snappy.BitShuffle; |
23 | 22 | import java.io.IOException; |
24 | 23 | import java.util.Arrays; |
25 | 24 |
|
26 | | - |
27 | 25 | public class BitShuffleFuzzer { |
| 26 | + private static final int SIZE = 4096; |
| 27 | + |
28 | 28 | 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)); |
33 | 32 | } |
34 | 33 |
|
35 | | - static void fuzzBitshuffleInts(int[] original){ |
| 34 | + static void fuzzBitshuffleInts(int[] original) { |
36 | 35 | int[] result; |
37 | 36 |
|
38 | | - try{ |
| 37 | + try { |
39 | 38 | byte[] shuffledByteArray = BitShuffle.shuffle(original); |
40 | 39 | byte[] compressed = Snappy.compress(shuffledByteArray); |
41 | 40 | byte[] uncompressed = Snappy.uncompress(compressed); |
42 | 41 | result = BitShuffle.unshuffleIntArray(uncompressed); |
43 | | - } |
44 | | - catch( IOException e ){ |
| 42 | + } catch (IOException e) { |
45 | 43 | throw new RuntimeException(e); |
46 | 44 | } |
47 | | - |
48 | | - if(Arrays.equals(original,result) == false) |
49 | | - { |
| 45 | + |
| 46 | + if (!Arrays.equals(original, result)) { |
50 | 47 | throw new IllegalStateException("Original and uncompressed data are different"); |
51 | 48 | } |
| 49 | + } |
52 | 50 |
|
53 | | - }//fuzz_bitshuffle_ints |
54 | | - |
55 | | - static void fuzz_bitshuffle_longs(long[] original){ |
| 51 | + static void fuzzBitshuffleLongs(long[] original) { |
56 | 52 | long[] result; |
57 | 53 |
|
58 | | - try{ |
| 54 | + try { |
59 | 55 | byte[] shuffledByteArray = BitShuffle.shuffle(original); |
60 | 56 | byte[] compressed = Snappy.compress(shuffledByteArray); |
61 | 57 | byte[] uncompressed = Snappy.uncompress(compressed); |
62 | 58 | result = BitShuffle.unshuffleLongArray(uncompressed); |
63 | | - } |
64 | | - catch( IOException e ){ |
| 59 | + } catch (IOException e) { |
65 | 60 | throw new RuntimeException(e); |
66 | 61 | } |
67 | | - |
68 | | - if(Arrays.equals(original,result) == false) |
69 | | - { |
| 62 | + |
| 63 | + if (!Arrays.equals(original, result)) { |
70 | 64 | throw new IllegalStateException("Original and uncompressed data are different"); |
71 | 65 | } |
| 66 | + } |
72 | 67 |
|
73 | | - }//fuzz_bitshuffle_longs |
74 | | - |
75 | | - static void fuzz_bitshuffle_shorts(short[] original){ |
| 68 | + static void fuzzBitshuffleShorts(short[] original) { |
76 | 69 | short[] result; |
77 | 70 |
|
78 | | - try{ |
| 71 | + try { |
79 | 72 | byte[] shuffledByteArray = BitShuffle.shuffle(original); |
80 | 73 | byte[] compressed = Snappy.compress(shuffledByteArray); |
81 | 74 | byte[] uncompressed = Snappy.uncompress(compressed); |
82 | 75 | result = BitShuffle.unshuffleShortArray(uncompressed); |
83 | | - } |
84 | | - catch( IOException e ){ |
| 76 | + } catch (IOException e) { |
85 | 77 | throw new RuntimeException(e); |
86 | 78 | } |
87 | | - |
88 | | - if(Arrays.equals(original,result) == false) |
89 | | - { |
| 79 | + |
| 80 | + if (!Arrays.equals(original, result)) { |
90 | 81 | throw new IllegalStateException("Original and uncompressed data are different"); |
91 | 82 | } |
92 | | - |
93 | | - }//fuzz_bitshuffle_shorts |
94 | | - |
| 83 | + } |
95 | 84 | } |
96 | | - |
0 commit comments