-
Notifications
You must be signed in to change notification settings - Fork 251
Add fuzzing targets for snappy-java #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 19 commits
7fcc441
0e8f777
e5ee759
ec6e0eb
975dcf4
abc1da5
8d1a144
5ce9139
a2552c5
11e14eb
f0f429f
0216f92
d4cd518
3bd4cd5
66a6e9a
ba47422
363eb19
cf0ca81
4fb7af6
528015f
ff76e20
4640f7b
b0566b6
97aca26
5a14675
cabae22
d19fb3b
25ade37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: CIFuzz | ||
| on: [pull_request] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| Fuzzing: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Build Fuzzers | ||
| id: build | ||
| uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master | ||
| with: | ||
| oss-fuzz-project-name: 'snappy-java' | ||
| dry-run: false | ||
| - name: Run Fuzzers | ||
| uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master | ||
| with: | ||
| oss-fuzz-project-name: 'snappy-java' | ||
| fuzz-seconds: 600 | ||
| dry-run: false | ||
| - name: Upload Crash | ||
| uses: actions/upload-artifact@v4 | ||
| if: failure() && steps.build.outcome == 'success' | ||
| with: | ||
| name: artifacts | ||
| path: ./out/artifacts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright 2023 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| package org.xerial.snappy.fuzz; | ||
|
|
||
| import com.code_intelligence.jazzer.api.FuzzedDataProvider; | ||
| import org.xerial.snappy.Snappy; | ||
| import org.xerial.snappy.BitShuffle; | ||
| import java.util.Arrays; | ||
|
|
||
| public class BitShuffleFuzzer { | ||
| private static final int SIZE = 4096; | ||
|
|
||
| public static void fuzzerTestOneInput(FuzzedDataProvider data) { | ||
| fuzzBitshuffleInts(data.consumeInts(SIZE)); | ||
| fuzzBitshuffleLongs(data.consumeLongs(SIZE)); | ||
| fuzzBitshuffleShorts(data.consumeShorts(SIZE)); | ||
| } | ||
|
vishalcoc44 marked this conversation as resolved.
|
||
|
|
||
| private static void runFuzz(RunnableWithException block) { | ||
| try { | ||
| block.run(); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
Comment on lines
+30
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test cases for empty arrays (5-9) are redundant. The switch (data.consumeInt(0, 4)) {
case 0:
fuzzBitshuffle(data.consumeInts(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleIntArray, "int[]");
break;
case 1:
fuzzBitshuffle(data.consumeLongs(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleLongArray, "long[]");
break;
case 2:
fuzzBitshuffle(data.consumeShorts(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleShortArray, "short[]");
break;
case 3:
fuzzBitshuffle(data.consumeFloats(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleFloatArray, "float[]");
break;
case 4:
fuzzBitshuffle(data.consumeDoubles(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleDoubleArray, "double[]");
break;
} |
||
| } | ||
|
|
||
| @FunctionalInterface | ||
| private interface RunnableWithException { | ||
| void run() throws Exception; | ||
| } | ||
|
vishalcoc44 marked this conversation as resolved.
|
||
|
|
||
| private static void fuzzBitshuffleInts(int[] original) { | ||
| runFuzz(() -> { | ||
| byte[] shuffledByteArray = BitShuffle.shuffle(original); | ||
| byte[] compressed = Snappy.compress(shuffledByteArray); | ||
| byte[] uncompressed = Snappy.uncompress(compressed); | ||
| int[] result = BitShuffle.unshuffleIntArray(uncompressed); | ||
| if (!Arrays.equals(original, result)) { | ||
| throw new IllegalStateException("Original and uncompressed data are different"); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private static void fuzzBitshuffleLongs(long[] original) { | ||
| runFuzz(() -> { | ||
| byte[] shuffledByteArray = BitShuffle.shuffle(original); | ||
| byte[] compressed = Snappy.compress(shuffledByteArray); | ||
| byte[] uncompressed = Snappy.uncompress(compressed); | ||
| long[] result = BitShuffle.unshuffleLongArray(uncompressed); | ||
| if (!Arrays.equals(original, result)) { | ||
| throw new IllegalStateException("Original and uncompressed data are different"); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private static void fuzzBitshuffleShorts(short[] original) { | ||
| runFuzz(() -> { | ||
| byte[] shuffledByteArray = BitShuffle.shuffle(original); | ||
| byte[] compressed = Snappy.compress(shuffledByteArray); | ||
| byte[] uncompressed = Snappy.uncompress(compressed); | ||
| short[] result = BitShuffle.unshuffleShortArray(uncompressed); | ||
| if (!Arrays.equals(original, result)) { | ||
| throw new IllegalStateException("Original and uncompressed data are different"); | ||
| } | ||
| }); | ||
| } | ||
|
vishalcoc44 marked this conversation as resolved.
Outdated
vishalcoc44 marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.