From 7fcc4415ab159984deac87085dc503fceeb12c26 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 00:51:25 +0530 Subject: [PATCH 01/23] Add fuzzing targets for snappy-java --- .github/workflows/cifuzz.yml | 32 ++ .../xerial/snappy/fuzz/BitShuffleFuzzer.java | 96 +++++ .../snappy/fuzz/SnappyCombinedFuzzer.java | 343 ++++++++++++++++++ .../snappy/fuzz/SnappyStreamFuzzer.java | 62 ++++ 4 files changed, 533 insertions(+) create mode 100644 .github/workflows/cifuzz.yml create mode 100644 src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java create mode 100644 src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java create mode 100644 src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml new file mode 100644 index 00000000..17b8c56f --- /dev/null +++ b/.github/workflows/cifuzz.yml @@ -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 diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java new file mode 100644 index 00000000..041ef010 --- /dev/null +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -0,0 +1,96 @@ +// 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.io.IOException; +import java.util.Arrays; + + +public class BitShuffleFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + int SIZE = 4096; + fuzz_bitshuffle_ints(data.consumeInts(SIZE)); + fuzz_bitshuffle_longs(data.consumeLongs(SIZE)); + fuzz_bitshuffle_shorts(data.consumeShorts(SIZE)); + } + + static void fuzz_bitshuffle_ints(int[] original){ + int[] result; + + try{ + byte[] shuffledByteArray = BitShuffle.shuffle(original); + byte[] compressed = Snappy.compress(shuffledByteArray); + byte[] uncompressed = Snappy.uncompress(compressed); + result = BitShuffle.unshuffleIntArray(uncompressed); + } + catch( IOException e ){ + return; + } + + if(Arrays.equals(original,result) == false) + { + throw new IllegalStateException("Original and uncompressed data are different"); + } + + }//fuzz_bitshuffle_ints + + static void fuzz_bitshuffle_longs(long[] original){ + long[] result; + + try{ + byte[] shuffledByteArray = BitShuffle.shuffle(original); + byte[] compressed = Snappy.compress(shuffledByteArray); + byte[] uncompressed = Snappy.uncompress(compressed); + result = BitShuffle.unshuffleLongArray(uncompressed); + } + catch( IOException e ){ + return; + } + + if(Arrays.equals(original,result) == false) + { + throw new IllegalStateException("Original and uncompressed data are different"); + } + + }//fuzz_bitshuffle_longs + + static void fuzz_bitshuffle_shorts(short[] original){ + short[] result; + + try{ + byte[] shuffledByteArray = BitShuffle.shuffle(original); + byte[] compressed = Snappy.compress(shuffledByteArray); + byte[] uncompressed = Snappy.uncompress(compressed); + result = BitShuffle.unshuffleShortArray(uncompressed); + } + catch( IOException e ){ + return; + } + + if(Arrays.equals(original,result) == false) + { + throw new IllegalStateException("Original and uncompressed data are different"); + } + + }//fuzz_bitshuffle_shorts + +} + diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java new file mode 100644 index 00000000..23351f0a --- /dev/null +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -0,0 +1,343 @@ +// 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.SnappyFramedInputStream; +import org.xerial.snappy.SnappyFramedOutputStream; +import org.xerial.snappy.SnappyInputStream; +import org.xerial.snappy.SnappyOutputStream; +import org.xerial.snappy.SnappyHadoopCompatibleOutputStream; +import org.xerial.snappy.BitShuffle; +import org.xerial.snappy.PureJavaCrc32C; +import java.nio.ByteBuffer; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; + +public class SnappyCombinedFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + int selector = data.consumeInt(0, 7); + switch (selector) { + case 0: + testRawApi(data); + break; + case 1: + testFramed(data); + break; + case 2: + testCrc32C(data); + break; + case 3: + testBlockStream(data); + break; + case 4: + testUtil(data); + break; + case 5: + testBitShuffle(data); + break; + case 6: + testHadoopStream(data); + break; + case 7: + testByteBuffer(data); + break; + } + } + + private static void testRawApi(FuzzedDataProvider data) { + byte[] input = data.consumeRemainingAsBytes(); + + try { + byte[] compressed = Snappy.compress(input); + byte[] uncompressed = Snappy.uncompress(compressed); + if (!Arrays.equals(input, uncompressed)) { + throw new IllegalStateException("Raw compress/uncompress failed"); + } + } catch (Exception e) { + } + + try { + byte[] rawCompressed = Snappy.rawCompress(input, input.length); + int uncompressedLen = Snappy.uncompressedLength(rawCompressed); + byte[] rawUncompressed = new byte[uncompressedLen]; + Snappy.rawUncompress(rawCompressed, 0, rawCompressed.length, rawUncompressed, 0); + } catch (Exception e) { + } + + try { + Snappy.isValidCompressedBuffer(input); + Snappy.isValidCompressedBuffer(input, 0, input.length); + } catch (Exception e) { + } + + try { + int maxLen = Snappy.maxCompressedLength(input.length); + if (maxLen < input.length) { + throw new IllegalStateException("maxCompressedLength too small"); + } + } catch (Exception e) { + } + + try { + byte[] compressed = Snappy.compress(input); + int len = Snappy.uncompressedLength(compressed); + int len2 = Snappy.uncompressedLength(compressed, 0, compressed.length); + } catch (Exception e) { + } + + try { + int[] intInput = data.consumeInts(100); + byte[] compressedInts = Snappy.compress(intInput); + int[] uncompressedInts = Snappy.uncompressIntArray(compressedInts); + } catch (Exception e) { + } + + try { + long[] longInput = data.consumeLongs(50); + byte[] compressedLongs = Snappy.compress(longInput); + long[] uncompressedLongs = Snappy.uncompressLongArray(compressedLongs); + } catch (Exception e) { + } + } + + private static void testFramed(FuzzedDataProvider data) { + byte[] original = data.consumeRemainingAsBytes(); + + try { + ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); + SnappyFramedOutputStream framedOut = new SnappyFramedOutputStream(compressedBuf); + framedOut.write(original); + framedOut.close(); + byte[] compressed = compressedBuf.toByteArray(); + + for (int bufferSize : new int[]{1, 64, 256, 1024, 4096}) { + SnappyFramedInputStream framedIn = new SnappyFramedInputStream( + new ByteArrayInputStream(compressed), true); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[bufferSize]; + int readBytes; + while ((readBytes = framedIn.read(buf)) != -1) { + out.write(buf, 0, readBytes); + } + out.flush(); + } + } catch (IOException e) { + } + + try { + byte[] invalidData = data.consumeBytes(100); + SnappyFramedInputStream invalidIn = new SnappyFramedInputStream( + new ByteArrayInputStream(invalidData)); + while (invalidIn.read() != -1) {} + } catch (IOException e) { + } + } + + private static void testCrc32C(FuzzedDataProvider data) { + byte[] input = data.consumeRemainingAsBytes(); + PureJavaCrc32C crc = new PureJavaCrc32C(); + + crc.update(input, 0, input.length); + long value = crc.getValue(); + + int intValue = crc.getIntegerValue(); + + crc.reset(); + crc.update(input, 0, input.length); + long value2 = crc.getValue(); + + PureJavaCrc32C crcChunked = new PureJavaCrc32C(); + for (int i = 0; i < Math.min(input.length, 1000); i++) { + crcChunked.update(input[i] & 0xFF); + } + + if (input.length > 2) { + byte[] partial1 = data.consumeBytes(Math.min(10, input.length)); + byte[] partial2 = data.consumeBytes(Math.min(10, input.length)); + + PureJavaCrc32C crc1 = new PureJavaCrc32C(); + crc1.update(input, 0, input.length); + + PureJavaCrc32C crc2 = new PureJavaCrc32C(); + crc2.update(partial1, 0, partial1.length); + crc2.update(partial2, 0, partial2.length); + } + + PureJavaCrc32C crcEmpty = new PureJavaCrc32C(); + crcEmpty.update(new byte[0], 0, 0); + long emptyValue = crcEmpty.getValue(); + + if (input.length > 0) { + PureJavaCrc32C crcSingle = new PureJavaCrc32C(); + crcSingle.update(input[0] & 0xFF); + } + + if (input.length > 4) { + PureJavaCrc32C crcOffset = new PureJavaCrc32C(); + crcOffset.update(input, 1, input.length - 1); + } + } + + private static void testBlockStream(FuzzedDataProvider data) { + byte[] original = data.consumeRemainingAsBytes(); + + try { + ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); + SnappyOutputStream out = new SnappyOutputStream(compressedBuf, -1); + out.write(original); + out.close(); + byte[] compressed = compressedBuf.toByteArray(); + + SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(compressed)); + ByteArrayOutputStream result = new ByteArrayOutputStream(); + byte[] buf = new byte[1024]; + int read; + while ((read = in.read(buf)) != -1) { + result.write(buf, 0, read); + } + in.close(); + } catch (Exception e) { + } + + try { + byte[] invalid = data.consumeBytes(100); + SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(invalid)); + while (in.read() != -1) {} + } catch (Exception e) { + } + } + + private static void testUtil(FuzzedDataProvider data) { + byte[] input = data.consumeRemainingAsBytes(); + + try { + String str = new String(input, java.nio.charset.StandardCharsets.UTF_8); + byte[] compressed = Snappy.compress(str); + String uncompressed = Snappy.uncompressString(compressed); + } catch (Exception e) { + } + + try { + int maxLen = Snappy.maxCompressedLength(input.length); + } catch (Exception e) { + } + + try { + short[] shortInput = new short[Math.min(100, input.length / 2)]; + for (int i = 0; i < shortInput.length; i++) { + shortInput[i] = (short) data.consumeInt(); + } + byte[] compressedShorts = Snappy.compress(shortInput); + short[] uncompressedShorts = Snappy.uncompressShortArray(compressedShorts); + } catch (Exception e) { + } + + try { + char[] charInput = new char[Math.min(100, input.length)]; + for (int i = 0; i < charInput.length; i++) { + charInput[i] = (char) data.consumeInt(); + } + byte[] compressedChars = Snappy.compress(charInput); + char[] uncompressedChars = Snappy.uncompressCharArray(compressedChars); + } catch (Exception e) { + } + } + + private static void testBitShuffle(FuzzedDataProvider data) { + try { + int[] intInput = data.consumeInts(100); + byte[] shuffled = BitShuffle.shuffle(intInput); + int[] unshuffled = BitShuffle.unshuffleIntArray(shuffled); + } catch (Exception e) { + } + + try { + long[] longInput = data.consumeLongs(50); + byte[] shuffled = BitShuffle.shuffle(longInput); + long[] unshuffled = BitShuffle.unshuffleLongArray(shuffled); + } catch (Exception e) { + } + + try { + short[] shortInput = data.consumeShorts(100); + byte[] shuffled = BitShuffle.shuffle(shortInput); + short[] unshuffled = BitShuffle.unshuffleShortArray(shuffled); + } catch (Exception e) { + } + } + + private static void testHadoopStream(FuzzedDataProvider data) { + byte[] original = data.consumeRemainingAsBytes(); + + try { + ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); + SnappyHadoopCompatibleOutputStream out = new SnappyHadoopCompatibleOutputStream(compressedBuf); + out.write(original); + out.close(); + byte[] compressed = compressedBuf.toByteArray(); + + SnappyInputStream in = new SnappyInputStream( + new ByteArrayInputStream(compressed)); + ByteArrayOutputStream result = new ByteArrayOutputStream(); + byte[] buf = new byte[1024]; + int read; + while ((read = in.read(buf)) != -1) { + result.write(buf, 0, read); + } + in.close(); + } catch (Exception e) { + } + } + + private static void testByteBuffer(FuzzedDataProvider data) { + byte[] input = data.consumeRemainingAsBytes(); + + try { + ByteBuffer src = ByteBuffer.wrap(input); + ByteBuffer dst = ByteBuffer.allocate(Snappy.maxCompressedLength(input.length)); + int compressed = Snappy.compress(src, dst); + + dst.limit(compressed); + dst.position(0); + ByteBuffer uncompressedBuf = ByteBuffer.allocate(input.length); + int uncompressed = Snappy.uncompress(dst, uncompressedBuf); + + uncompressedBuf.limit(uncompressed); + byte[] result = new byte[uncompressed]; + uncompressedBuf.get(result); + + if (!Arrays.equals(input, result)) { + throw new IllegalStateException("ByteBuffer compress failed"); + } + } catch (Exception e) { + } + + try { + ByteBuffer directSrc = ByteBuffer.allocateDirect(input.length); + directSrc.put(input); + directSrc.flip(); + + ByteBuffer directDst = ByteBuffer.allocateDirect(Snappy.maxCompressedLength(input.length)); + Snappy.compress(directSrc, directDst); + } catch (Exception e) { + } + } +} diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java new file mode 100644 index 00000000..8df4cc5e --- /dev/null +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -0,0 +1,62 @@ +// 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.SnappyInputStream; +import org.xerial.snappy.SnappyOutputStream; +import org.xerial.snappy.SnappyCodec; +import java.io.IOException; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.BufferedInputStream; +import java.util.Arrays; + +public class SnappyStreamFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + + byte[] original = data.consumeRemainingAsBytes(); + byte[] uncompressed; + + try { + ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); + SnappyOutputStream snappyOut = new SnappyOutputStream(compressedBuf); + snappyOut.write(original); + snappyOut.close(); + byte[] compressed = compressedBuf.toByteArray(); + SnappyInputStream snappyIn = new SnappyInputStream(new ByteArrayInputStream(compressed)); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[4096]; + for (int readBytes = 0; (readBytes = snappyIn.read(buf)) != -1; ) { + out.write(buf, 0, readBytes); + } + out.flush(); + uncompressed = out.toByteArray(); + } + catch (IOException e) + { + return; + } + + if(Arrays.equals(original,uncompressed) == false) + { + throw new IllegalStateException("Original and uncompressed data are different"); + } + } +} From 0e8f777d24fabdcf4be253b907315ea7b25f0161 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 01:19:13 +0530 Subject: [PATCH 02/23] minor changes --- .../org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 23351f0a..7ca9df15 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -311,16 +311,19 @@ private static void testByteBuffer(FuzzedDataProvider data) { byte[] input = data.consumeRemainingAsBytes(); try { - ByteBuffer src = ByteBuffer.wrap(input); - ByteBuffer dst = ByteBuffer.allocate(Snappy.maxCompressedLength(input.length)); + ByteBuffer src = ByteBuffer.allocateDirect(input.length); + src.put(input); + src.flip(); + ByteBuffer dst = ByteBuffer.allocateDirect(Snappy.maxCompressedLength(input.length)); int compressed = Snappy.compress(src, dst); dst.limit(compressed); dst.position(0); - ByteBuffer uncompressedBuf = ByteBuffer.allocate(input.length); + ByteBuffer uncompressedBuf = ByteBuffer.allocateDirect(input.length); int uncompressed = Snappy.uncompress(dst, uncompressedBuf); uncompressedBuf.limit(uncompressed); + uncompressedBuf.position(0); byte[] result = new byte[uncompressed]; uncompressedBuf.get(result); From e5ee759eb01195cee9dcdd1e91568ca339b93f7a Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:28:33 +0530 Subject: [PATCH 03/23] Update src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index 041ef010..16964b9c 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -42,7 +42,7 @@ static void fuzz_bitshuffle_ints(int[] original){ result = BitShuffle.unshuffleIntArray(uncompressed); } catch( IOException e ){ - return; + throw new RuntimeException(e); } if(Arrays.equals(original,result) == false) From ec6e0eb410a2576671697c3f310097a423d50003 Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:28:48 +0530 Subject: [PATCH 04/23] Update src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index 16964b9c..80d59b5a 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -62,7 +62,7 @@ static void fuzz_bitshuffle_longs(long[] original){ result = BitShuffle.unshuffleLongArray(uncompressed); } catch( IOException e ){ - return; + throw new RuntimeException(e); } if(Arrays.equals(original,result) == false) From 975dcf4d13a138408da78c60e4f9f9157b167334 Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:28:59 +0530 Subject: [PATCH 05/23] Update src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index 80d59b5a..b2d4b7a6 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -82,7 +82,7 @@ static void fuzz_bitshuffle_shorts(short[] original){ result = BitShuffle.unshuffleShortArray(uncompressed); } catch( IOException e ){ - return; + throw new RuntimeException(e); } if(Arrays.equals(original,result) == false) From abc1da58ef5fc1086d19eed703e0646f5e3e413f Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:29:09 +0530 Subject: [PATCH 06/23] Update src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 7ca9df15..267e9d33 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -72,6 +72,7 @@ private static void testRawApi(FuzzedDataProvider data) { throw new IllegalStateException("Raw compress/uncompress failed"); } } catch (Exception e) { + throw new RuntimeException(e); } try { From 8d1a14455be5ac27af834ae6819395e0edd4deef Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 01:37:35 +0530 Subject: [PATCH 07/23] resolved detection and reporting of crashes --- .../snappy/fuzz/SnappyCombinedFuzzer.java | 45 ++++++++++--------- .../snappy/fuzz/SnappyStreamFuzzer.java | 18 ++++---- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 267e9d33..270e2496 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -130,25 +130,26 @@ private static void testFramed(FuzzedDataProvider data) { byte[] compressed = compressedBuf.toByteArray(); for (int bufferSize : new int[]{1, 64, 256, 1024, 4096}) { - SnappyFramedInputStream framedIn = new SnappyFramedInputStream( - new ByteArrayInputStream(compressed), true); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buf = new byte[bufferSize]; - int readBytes; - while ((readBytes = framedIn.read(buf)) != -1) { - out.write(buf, 0, readBytes); + try (SnappyFramedInputStream framedIn = new SnappyFramedInputStream( + new ByteArrayInputStream(compressed), true)) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[bufferSize]; + int readBytes; + while ((readBytes = framedIn.read(buf)) != -1) { + out.write(buf, 0, readBytes); + } + out.flush(); } - out.flush(); } } catch (IOException e) { + throw new RuntimeException(e); } - try { - byte[] invalidData = data.consumeBytes(100); - SnappyFramedInputStream invalidIn = new SnappyFramedInputStream( - new ByteArrayInputStream(invalidData)); + try (SnappyFramedInputStream invalidIn = new SnappyFramedInputStream( + new ByteArrayInputStream(data.consumeBytes(100)))) { while (invalidIn.read() != -1) {} } catch (IOException e) { + throw new RuntimeException(e); } } @@ -207,22 +208,22 @@ private static void testBlockStream(FuzzedDataProvider data) { out.close(); byte[] compressed = compressedBuf.toByteArray(); - SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(compressed)); - ByteArrayOutputStream result = new ByteArrayOutputStream(); - byte[] buf = new byte[1024]; - int read; - while ((read = in.read(buf)) != -1) { - result.write(buf, 0, read); + try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(compressed))) { + ByteArrayOutputStream result = new ByteArrayOutputStream(); + byte[] buf = new byte[1024]; + int read; + while ((read = in.read(buf)) != -1) { + result.write(buf, 0, read); + } } - in.close(); } catch (Exception e) { + throw new RuntimeException(e); } - try { - byte[] invalid = data.consumeBytes(100); - SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(invalid)); + try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data.consumeBytes(100)))) { while (in.read() != -1) {} } catch (Exception e) { + throw new RuntimeException(e); } } diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index 8df4cc5e..5850fd9c 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -40,18 +40,20 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { snappyOut.write(original); snappyOut.close(); byte[] compressed = compressedBuf.toByteArray(); - SnappyInputStream snappyIn = new SnappyInputStream(new ByteArrayInputStream(compressed)); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buf = new byte[4096]; - for (int readBytes = 0; (readBytes = snappyIn.read(buf)) != -1; ) { - out.write(buf, 0, readBytes); + + try (SnappyInputStream snappyIn = new SnappyInputStream(new ByteArrayInputStream(compressed))) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[4096]; + for (int readBytes = 0; (readBytes = snappyIn.read(buf)) != -1; ) { + out.write(buf, 0, readBytes); + } + out.flush(); + uncompressed = out.toByteArray(); } - out.flush(); - uncompressed = out.toByteArray(); } catch (IOException e) { - return; + throw new RuntimeException(e); } if(Arrays.equals(original,uncompressed) == false) From 5ce913920ed54d0ebeb694074b3f724dec18c48d Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:48:32 +0530 Subject: [PATCH 08/23] Update src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 270e2496..9275545d 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -149,7 +149,7 @@ private static void testFramed(FuzzedDataProvider data) { new ByteArrayInputStream(data.consumeBytes(100)))) { while (invalidIn.read() != -1) {} } catch (IOException e) { - throw new RuntimeException(e); + // Expected, ignore. } } From a2552c5ed9825a455ea8b5742ead60e3d0ddef74 Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:48:48 +0530 Subject: [PATCH 09/23] Update src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 9275545d..6ca51435 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -223,7 +223,7 @@ private static void testBlockStream(FuzzedDataProvider data) { try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data.consumeBytes(100)))) { while (in.read() != -1) {} } catch (Exception e) { - throw new RuntimeException(e); + // Expected, ignore. } } From 11e14eb48e8429d3388ee2ba1d3f5c2aba1d8d76 Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:49:18 +0530 Subject: [PATCH 10/23] Update src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index b2d4b7a6..c2bec272 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -32,7 +32,7 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { fuzz_bitshuffle_shorts(data.consumeShorts(SIZE)); } - static void fuzz_bitshuffle_ints(int[] original){ + static void fuzzBitshuffleInts(int[] original){ int[] result; try{ From f0f429f2791e69f66a562d0fe4026a24056b3de6 Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:49:42 +0530 Subject: [PATCH 11/23] Update src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index 5850fd9c..65d1ec48 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -32,7 +32,7 @@ public class SnappyStreamFuzzer { public static void fuzzerTestOneInput(FuzzedDataProvider data) { byte[] original = data.consumeRemainingAsBytes(); - byte[] uncompressed; + byte[] uncompressed = null; try { ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); From 0216f923d02198fed3e6eee6b8dde2fa83f93a4f Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:49:55 +0530 Subject: [PATCH 12/23] Update src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index 65d1ec48..2f423786 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -44,7 +44,8 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { try (SnappyInputStream snappyIn = new SnappyInputStream(new ByteArrayInputStream(compressed))) { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; - for (int readBytes = 0; (readBytes = snappyIn.read(buf)) != -1; ) { + int readBytes; + while ((readBytes = snappyIn.read(buf)) != -1) { out.write(buf, 0, readBytes); } out.flush(); From d4cd518cd7058f4485bb3c293162708d58739b2d Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 01:54:49 +0530 Subject: [PATCH 13/23] - --- .../xerial/snappy/fuzz/BitShuffleFuzzer.java | 58 ++++++++----------- .../snappy/fuzz/SnappyStreamFuzzer.java | 11 +--- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index c2bec272..eedd5ed1 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -17,80 +17,68 @@ package org.xerial.snappy.fuzz; import com.code_intelligence.jazzer.api.FuzzedDataProvider; - import org.xerial.snappy.Snappy; import org.xerial.snappy.BitShuffle; import java.io.IOException; import java.util.Arrays; - public class BitShuffleFuzzer { + private static final int SIZE = 4096; + public static void fuzzerTestOneInput(FuzzedDataProvider data) { - int SIZE = 4096; - fuzz_bitshuffle_ints(data.consumeInts(SIZE)); - fuzz_bitshuffle_longs(data.consumeLongs(SIZE)); - fuzz_bitshuffle_shorts(data.consumeShorts(SIZE)); + fuzzBitshuffleInts(data.consumeInts(SIZE)); + fuzzBitshuffleLongs(data.consumeLongs(SIZE)); + fuzzBitshuffleShorts(data.consumeShorts(SIZE)); } - static void fuzzBitshuffleInts(int[] original){ + static void fuzzBitshuffleInts(int[] original) { int[] result; - try{ + try { byte[] shuffledByteArray = BitShuffle.shuffle(original); byte[] compressed = Snappy.compress(shuffledByteArray); byte[] uncompressed = Snappy.uncompress(compressed); result = BitShuffle.unshuffleIntArray(uncompressed); - } - catch( IOException e ){ + } catch (IOException e) { throw new RuntimeException(e); } - - if(Arrays.equals(original,result) == false) - { + + if (!Arrays.equals(original, result)) { throw new IllegalStateException("Original and uncompressed data are different"); } + } - }//fuzz_bitshuffle_ints - - static void fuzz_bitshuffle_longs(long[] original){ + static void fuzzBitshuffleLongs(long[] original) { long[] result; - try{ + try { byte[] shuffledByteArray = BitShuffle.shuffle(original); byte[] compressed = Snappy.compress(shuffledByteArray); byte[] uncompressed = Snappy.uncompress(compressed); result = BitShuffle.unshuffleLongArray(uncompressed); - } - catch( IOException e ){ + } catch (IOException e) { throw new RuntimeException(e); } - - if(Arrays.equals(original,result) == false) - { + + if (!Arrays.equals(original, result)) { throw new IllegalStateException("Original and uncompressed data are different"); } + } - }//fuzz_bitshuffle_longs - - static void fuzz_bitshuffle_shorts(short[] original){ + static void fuzzBitshuffleShorts(short[] original) { short[] result; - try{ + try { byte[] shuffledByteArray = BitShuffle.shuffle(original); byte[] compressed = Snappy.compress(shuffledByteArray); byte[] uncompressed = Snappy.uncompress(compressed); result = BitShuffle.unshuffleShortArray(uncompressed); - } - catch( IOException e ){ + } catch (IOException e) { throw new RuntimeException(e); } - - if(Arrays.equals(original,result) == false) - { + + if (!Arrays.equals(original, result)) { throw new IllegalStateException("Original and uncompressed data are different"); } - - }//fuzz_bitshuffle_shorts - + } } - diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index 2f423786..1b5110c5 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -17,15 +17,11 @@ package org.xerial.snappy.fuzz; import com.code_intelligence.jazzer.api.FuzzedDataProvider; - -import org.xerial.snappy.Snappy; import org.xerial.snappy.SnappyInputStream; import org.xerial.snappy.SnappyOutputStream; -import org.xerial.snappy.SnappyCodec; import java.io.IOException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.BufferedInputStream; import java.util.Arrays; public class SnappyStreamFuzzer { @@ -51,14 +47,11 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { out.flush(); uncompressed = out.toByteArray(); } - } - catch (IOException e) - { + } catch (IOException e) { throw new RuntimeException(e); } - if(Arrays.equals(original,uncompressed) == false) - { + if (!Arrays.equals(original, uncompressed)) { throw new IllegalStateException("Original and uncompressed data are different"); } } From 3bd4cd58161d7b9eb30ac29b823162c95cf92a70 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 02:05:22 +0530 Subject: [PATCH 14/23] - --- .../snappy/fuzz/SnappyCombinedFuzzer.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 6ca51435..0df80882 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -81,12 +81,14 @@ private static void testRawApi(FuzzedDataProvider data) { byte[] rawUncompressed = new byte[uncompressedLen]; Snappy.rawUncompress(rawCompressed, 0, rawCompressed.length, rawUncompressed, 0); } catch (Exception e) { + throw new RuntimeException(e); } try { Snappy.isValidCompressedBuffer(input); Snappy.isValidCompressedBuffer(input, 0, input.length); } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -95,6 +97,7 @@ private static void testRawApi(FuzzedDataProvider data) { throw new IllegalStateException("maxCompressedLength too small"); } } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -102,6 +105,7 @@ private static void testRawApi(FuzzedDataProvider data) { int len = Snappy.uncompressedLength(compressed); int len2 = Snappy.uncompressedLength(compressed, 0, compressed.length); } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -109,6 +113,7 @@ private static void testRawApi(FuzzedDataProvider data) { byte[] compressedInts = Snappy.compress(intInput); int[] uncompressedInts = Snappy.uncompressIntArray(compressedInts); } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -116,6 +121,7 @@ private static void testRawApi(FuzzedDataProvider data) { byte[] compressedLongs = Snappy.compress(longInput); long[] uncompressedLongs = Snappy.uncompressLongArray(compressedLongs); } catch (Exception e) { + throw new RuntimeException(e); } } @@ -149,7 +155,7 @@ private static void testFramed(FuzzedDataProvider data) { new ByteArrayInputStream(data.consumeBytes(100)))) { while (invalidIn.read() != -1) {} } catch (IOException e) { - // Expected, ignore. + throw new RuntimeException(e); } } @@ -223,7 +229,7 @@ private static void testBlockStream(FuzzedDataProvider data) { try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data.consumeBytes(100)))) { while (in.read() != -1) {} } catch (Exception e) { - // Expected, ignore. + throw new RuntimeException(e); } } @@ -235,11 +241,13 @@ private static void testUtil(FuzzedDataProvider data) { byte[] compressed = Snappy.compress(str); String uncompressed = Snappy.uncompressString(compressed); } catch (Exception e) { + throw new RuntimeException(e); } try { int maxLen = Snappy.maxCompressedLength(input.length); } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -250,6 +258,7 @@ private static void testUtil(FuzzedDataProvider data) { byte[] compressedShorts = Snappy.compress(shortInput); short[] uncompressedShorts = Snappy.uncompressShortArray(compressedShorts); } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -260,6 +269,7 @@ private static void testUtil(FuzzedDataProvider data) { byte[] compressedChars = Snappy.compress(charInput); char[] uncompressedChars = Snappy.uncompressCharArray(compressedChars); } catch (Exception e) { + throw new RuntimeException(e); } } @@ -269,6 +279,7 @@ private static void testBitShuffle(FuzzedDataProvider data) { byte[] shuffled = BitShuffle.shuffle(intInput); int[] unshuffled = BitShuffle.unshuffleIntArray(shuffled); } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -276,6 +287,7 @@ private static void testBitShuffle(FuzzedDataProvider data) { byte[] shuffled = BitShuffle.shuffle(longInput); long[] unshuffled = BitShuffle.unshuffleLongArray(shuffled); } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -283,6 +295,7 @@ private static void testBitShuffle(FuzzedDataProvider data) { byte[] shuffled = BitShuffle.shuffle(shortInput); short[] unshuffled = BitShuffle.unshuffleShortArray(shuffled); } catch (Exception e) { + throw new RuntimeException(e); } } @@ -296,16 +309,17 @@ private static void testHadoopStream(FuzzedDataProvider data) { out.close(); byte[] compressed = compressedBuf.toByteArray(); - SnappyInputStream in = new SnappyInputStream( - new ByteArrayInputStream(compressed)); - ByteArrayOutputStream result = new ByteArrayOutputStream(); - byte[] buf = new byte[1024]; - int read; - while ((read = in.read(buf)) != -1) { - result.write(buf, 0, read); + try (SnappyInputStream in = new SnappyInputStream( + new ByteArrayInputStream(compressed))) { + ByteArrayOutputStream result = new ByteArrayOutputStream(); + byte[] buf = new byte[1024]; + int read; + while ((read = in.read(buf)) != -1) { + result.write(buf, 0, read); + } } - in.close(); } catch (Exception e) { + throw new RuntimeException(e); } } @@ -333,6 +347,7 @@ private static void testByteBuffer(FuzzedDataProvider data) { throw new IllegalStateException("ByteBuffer compress failed"); } } catch (Exception e) { + throw new RuntimeException(e); } try { @@ -343,6 +358,7 @@ private static void testByteBuffer(FuzzedDataProvider data) { ByteBuffer directDst = ByteBuffer.allocateDirect(Snappy.maxCompressedLength(input.length)); Snappy.compress(directSrc, directDst); } catch (Exception e) { + throw new RuntimeException(e); } } } From 66a6e9a915820ab95c2098f24a6a97dfe82374d2 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 09:44:16 +0530 Subject: [PATCH 15/23] - --- .../snappy/fuzz/SnappyCombinedFuzzer.java | 174 ++++++++---------- 1 file changed, 80 insertions(+), 94 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 0df80882..d5e6841f 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -32,6 +32,19 @@ import java.util.Arrays; public class SnappyCombinedFuzzer { + + private interface FuzzBlock { + void run() throws Exception; + } + + private static void runFuzz(FuzzBlock block) { + try { + block.run(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + public static void fuzzerTestOneInput(FuzzedDataProvider data) { int selector = data.consumeInt(0, 7); switch (selector) { @@ -65,70 +78,56 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { private static void testRawApi(FuzzedDataProvider data) { byte[] input = data.consumeRemainingAsBytes(); - try { + runFuzz(() -> { byte[] compressed = Snappy.compress(input); byte[] uncompressed = Snappy.uncompress(compressed); if (!Arrays.equals(input, uncompressed)) { throw new IllegalStateException("Raw compress/uncompress failed"); } - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { byte[] rawCompressed = Snappy.rawCompress(input, input.length); int uncompressedLen = Snappy.uncompressedLength(rawCompressed); byte[] rawUncompressed = new byte[uncompressedLen]; Snappy.rawUncompress(rawCompressed, 0, rawCompressed.length, rawUncompressed, 0); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { Snappy.isValidCompressedBuffer(input); Snappy.isValidCompressedBuffer(input, 0, input.length); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { int maxLen = Snappy.maxCompressedLength(input.length); if (maxLen < input.length) { throw new IllegalStateException("maxCompressedLength too small"); } - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { byte[] compressed = Snappy.compress(input); int len = Snappy.uncompressedLength(compressed); int len2 = Snappy.uncompressedLength(compressed, 0, compressed.length); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { int[] intInput = data.consumeInts(100); byte[] compressedInts = Snappy.compress(intInput); int[] uncompressedInts = Snappy.uncompressIntArray(compressedInts); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { long[] longInput = data.consumeLongs(50); byte[] compressedLongs = Snappy.compress(longInput); long[] uncompressedLongs = Snappy.uncompressLongArray(compressedLongs); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); } private static void testFramed(FuzzedDataProvider data) { byte[] original = data.consumeRemainingAsBytes(); - try { + runFuzz(() -> { ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); SnappyFramedOutputStream framedOut = new SnappyFramedOutputStream(compressedBuf); framedOut.write(original); @@ -147,22 +146,22 @@ private static void testFramed(FuzzedDataProvider data) { out.flush(); } } - } catch (IOException e) { - throw new RuntimeException(e); - } + }); - try (SnappyFramedInputStream invalidIn = new SnappyFramedInputStream( - new ByteArrayInputStream(data.consumeBytes(100)))) { - while (invalidIn.read() != -1) {} - } catch (IOException e) { - throw new RuntimeException(e); - } + runFuzz(() -> { + try (SnappyFramedInputStream invalidIn = new SnappyFramedInputStream( + new ByteArrayInputStream(data.consumeBytes(100)))) { + while (invalidIn.read() != -1) {} + } + }); } private static void testCrc32C(FuzzedDataProvider data) { byte[] input = data.consumeRemainingAsBytes(); - PureJavaCrc32C crc = new PureJavaCrc32C(); + byte[] chunk1 = data.consumeBytes(50); + byte[] chunk2 = data.consumeBytes(50); + PureJavaCrc32C crc = new PureJavaCrc32C(); crc.update(input, 0, input.length); long value = crc.getValue(); @@ -171,22 +170,22 @@ private static void testCrc32C(FuzzedDataProvider data) { crc.reset(); crc.update(input, 0, input.length); long value2 = crc.getValue(); + if (value != value2) { + throw new IllegalStateException("CRC32C reset produced different value"); + } PureJavaCrc32C crcChunked = new PureJavaCrc32C(); for (int i = 0; i < Math.min(input.length, 1000); i++) { crcChunked.update(input[i] & 0xFF); } - if (input.length > 2) { - byte[] partial1 = data.consumeBytes(Math.min(10, input.length)); - byte[] partial2 = data.consumeBytes(Math.min(10, input.length)); - + if (chunk1.length > 0 && chunk2.length > 0) { PureJavaCrc32C crc1 = new PureJavaCrc32C(); crc1.update(input, 0, input.length); PureJavaCrc32C crc2 = new PureJavaCrc32C(); - crc2.update(partial1, 0, partial1.length); - crc2.update(partial2, 0, partial2.length); + crc2.update(chunk1, 0, chunk1.length); + crc2.update(chunk2, 0, chunk2.length); } PureJavaCrc32C crcEmpty = new PureJavaCrc32C(); @@ -207,7 +206,7 @@ private static void testCrc32C(FuzzedDataProvider data) { private static void testBlockStream(FuzzedDataProvider data) { byte[] original = data.consumeRemainingAsBytes(); - try { + runFuzz(() -> { ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); SnappyOutputStream out = new SnappyOutputStream(compressedBuf, -1); out.write(original); @@ -222,87 +221,80 @@ private static void testBlockStream(FuzzedDataProvider data) { result.write(buf, 0, read); } } - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data.consumeBytes(100)))) { - while (in.read() != -1) {} - } catch (Exception e) { - throw new RuntimeException(e); - } + runFuzz(() -> { + try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data.consumeBytes(100)))) { + while (in.read() != -1) {} + } + }); } private static void testUtil(FuzzedDataProvider data) { byte[] input = data.consumeRemainingAsBytes(); - try { + runFuzz(() -> { String str = new String(input, java.nio.charset.StandardCharsets.UTF_8); byte[] compressed = Snappy.compress(str); String uncompressed = Snappy.uncompressString(compressed); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { int maxLen = Snappy.maxCompressedLength(input.length); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { short[] shortInput = new short[Math.min(100, input.length / 2)]; for (int i = 0; i < shortInput.length; i++) { shortInput[i] = (short) data.consumeInt(); } byte[] compressedShorts = Snappy.compress(shortInput); short[] uncompressedShorts = Snappy.uncompressShortArray(compressedShorts); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { char[] charInput = new char[Math.min(100, input.length)]; for (int i = 0; i < charInput.length; i++) { charInput[i] = (char) data.consumeInt(); } byte[] compressedChars = Snappy.compress(charInput); char[] uncompressedChars = Snappy.uncompressCharArray(compressedChars); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); } private static void testBitShuffle(FuzzedDataProvider data) { - try { + runFuzz(() -> { int[] intInput = data.consumeInts(100); byte[] shuffled = BitShuffle.shuffle(intInput); int[] unshuffled = BitShuffle.unshuffleIntArray(shuffled); - } catch (Exception e) { - throw new RuntimeException(e); - } + if (!Arrays.equals(intInput, unshuffled)) { + throw new IllegalStateException("BitShuffle int failed"); + } + }); - try { + runFuzz(() -> { long[] longInput = data.consumeLongs(50); byte[] shuffled = BitShuffle.shuffle(longInput); long[] unshuffled = BitShuffle.unshuffleLongArray(shuffled); - } catch (Exception e) { - throw new RuntimeException(e); - } + if (!Arrays.equals(longInput, unshuffled)) { + throw new IllegalStateException("BitShuffle long failed"); + } + }); - try { + runFuzz(() -> { short[] shortInput = data.consumeShorts(100); byte[] shuffled = BitShuffle.shuffle(shortInput); short[] unshuffled = BitShuffle.unshuffleShortArray(shuffled); - } catch (Exception e) { - throw new RuntimeException(e); - } + if (!Arrays.equals(shortInput, unshuffled)) { + throw new IllegalStateException("BitShuffle short failed"); + } + }); } private static void testHadoopStream(FuzzedDataProvider data) { byte[] original = data.consumeRemainingAsBytes(); - try { + runFuzz(() -> { ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); SnappyHadoopCompatibleOutputStream out = new SnappyHadoopCompatibleOutputStream(compressedBuf); out.write(original); @@ -318,15 +310,13 @@ private static void testHadoopStream(FuzzedDataProvider data) { result.write(buf, 0, read); } } - } catch (Exception e) { - throw new RuntimeException(e); - } + }); } private static void testByteBuffer(FuzzedDataProvider data) { byte[] input = data.consumeRemainingAsBytes(); - try { + runFuzz(() -> { ByteBuffer src = ByteBuffer.allocateDirect(input.length); src.put(input); src.flip(); @@ -346,19 +336,15 @@ private static void testByteBuffer(FuzzedDataProvider data) { if (!Arrays.equals(input, result)) { throw new IllegalStateException("ByteBuffer compress failed"); } - } catch (Exception e) { - throw new RuntimeException(e); - } + }); - try { + runFuzz(() -> { ByteBuffer directSrc = ByteBuffer.allocateDirect(input.length); directSrc.put(input); directSrc.flip(); ByteBuffer directDst = ByteBuffer.allocateDirect(Snappy.maxCompressedLength(input.length)); Snappy.compress(directSrc, directDst); - } catch (Exception e) { - throw new RuntimeException(e); - } + }); } } From ba474229c83fbac0b42d18ed7371306fce603edc Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 09:55:21 +0530 Subject: [PATCH 16/23] - --- .../snappy/fuzz/SnappyCombinedFuzzer.java | 131 +++++++++++------- 1 file changed, 81 insertions(+), 50 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index d5e6841f..347eb562 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -76,64 +76,84 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { } private static void testRawApi(FuzzedDataProvider data) { - byte[] input = data.consumeRemainingAsBytes(); - runFuzz(() -> { + byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); byte[] compressed = Snappy.compress(input); byte[] uncompressed = Snappy.uncompress(compressed); if (!Arrays.equals(input, uncompressed)) { throw new IllegalStateException("Raw compress/uncompress failed"); } }); - + runFuzz(() -> { + byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); byte[] rawCompressed = Snappy.rawCompress(input, input.length); - int uncompressedLen = Snappy.uncompressedLength(rawCompressed); - byte[] rawUncompressed = new byte[uncompressedLen]; - Snappy.rawUncompress(rawCompressed, 0, rawCompressed.length, rawUncompressed, 0); + if (Snappy.isValidCompressedBuffer(rawCompressed)) { + int uncompressedLen = Snappy.uncompressedLength(rawCompressed); + if (uncompressedLen == input.length) { + byte[] rawUncompressed = new byte[uncompressedLen]; + Snappy.rawUncompress(rawCompressed, 0, rawCompressed.length, rawUncompressed, 0); + if (!Arrays.equals(input, rawUncompressed)) { + throw new IllegalStateException("Raw compress/uncompress with byte[] failed"); + } + } + } }); - + runFuzz(() -> { + byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); Snappy.isValidCompressedBuffer(input); Snappy.isValidCompressedBuffer(input, 0, input.length); }); - + runFuzz(() -> { - int maxLen = Snappy.maxCompressedLength(input.length); - if (maxLen < input.length) { + int inputLength = data.consumeInt(0, 4096); + int maxLen = Snappy.maxCompressedLength(inputLength); + if (maxLen < inputLength) { throw new IllegalStateException("maxCompressedLength too small"); } }); - + runFuzz(() -> { + byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); byte[] compressed = Snappy.compress(input); - int len = Snappy.uncompressedLength(compressed); - int len2 = Snappy.uncompressedLength(compressed, 0, compressed.length); + if (Snappy.isValidCompressedBuffer(compressed)) { + int len = Snappy.uncompressedLength(compressed); + int len2 = Snappy.uncompressedLength(compressed, 0, compressed.length); + if (len != input.length || len2 != input.length) { + throw new IllegalStateException("uncompressedLength did not match original length"); + } + } }); - + runFuzz(() -> { - int[] intInput = data.consumeInts(100); + int[] intInput = data.consumeInts(data.consumeInt(0, 100)); byte[] compressedInts = Snappy.compress(intInput); int[] uncompressedInts = Snappy.uncompressIntArray(compressedInts); + if (!Arrays.equals(intInput, uncompressedInts)) { + throw new IllegalStateException("Int array roundtrip failed"); + } }); - + runFuzz(() -> { - long[] longInput = data.consumeLongs(50); + long[] longInput = data.consumeLongs(data.consumeInt(0, 50)); byte[] compressedLongs = Snappy.compress(longInput); long[] uncompressedLongs = Snappy.uncompressLongArray(compressedLongs); + if (!Arrays.equals(longInput, uncompressedLongs)) { + throw new IllegalStateException("Long array roundtrip failed"); + } }); } private static void testFramed(FuzzedDataProvider data) { - byte[] original = data.consumeRemainingAsBytes(); - runFuzz(() -> { + byte[] original = data.consumeBytes(data.consumeInt(0, 4096)); ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); SnappyFramedOutputStream framedOut = new SnappyFramedOutputStream(compressedBuf); framedOut.write(original); framedOut.close(); byte[] compressed = compressedBuf.toByteArray(); - + for (int bufferSize : new int[]{1, 64, 256, 1024, 4096}) { try (SnappyFramedInputStream framedIn = new SnappyFramedInputStream( new ByteArrayInputStream(compressed), true)) { @@ -143,11 +163,13 @@ private static void testFramed(FuzzedDataProvider data) { while ((readBytes = framedIn.read(buf)) != -1) { out.write(buf, 0, readBytes); } - out.flush(); + if (!Arrays.equals(original, out.toByteArray())) { + throw new IllegalStateException("Framed stream roundtrip failed"); + } } } }); - + runFuzz(() -> { try (SnappyFramedInputStream invalidIn = new SnappyFramedInputStream( new ByteArrayInputStream(data.consumeBytes(100)))) { @@ -157,7 +179,7 @@ private static void testFramed(FuzzedDataProvider data) { } private static void testCrc32C(FuzzedDataProvider data) { - byte[] input = data.consumeRemainingAsBytes(); + byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); byte[] chunk1 = data.consumeBytes(50); byte[] chunk2 = data.consumeBytes(50); @@ -204,15 +226,14 @@ private static void testCrc32C(FuzzedDataProvider data) { } private static void testBlockStream(FuzzedDataProvider data) { - byte[] original = data.consumeRemainingAsBytes(); - runFuzz(() -> { + byte[] original = data.consumeBytes(data.consumeInt(0, 4096)); ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); SnappyOutputStream out = new SnappyOutputStream(compressedBuf, -1); out.write(original); out.close(); byte[] compressed = compressedBuf.toByteArray(); - + try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(compressed))) { ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; @@ -220,9 +241,12 @@ private static void testBlockStream(FuzzedDataProvider data) { while ((read = in.read(buf)) != -1) { result.write(buf, 0, read); } + if (!Arrays.equals(original, result.toByteArray())) { + throw new IllegalStateException("Block stream roundtrip failed"); + } } }); - + runFuzz(() -> { try (SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data.consumeBytes(100)))) { while (in.read() != -1) {} @@ -231,40 +255,45 @@ private static void testBlockStream(FuzzedDataProvider data) { } private static void testUtil(FuzzedDataProvider data) { - byte[] input = data.consumeRemainingAsBytes(); - runFuzz(() -> { - String str = new String(input, java.nio.charset.StandardCharsets.UTF_8); + String str = data.consumeString(data.consumeInt(0, 4096)); byte[] compressed = Snappy.compress(str); String uncompressed = Snappy.uncompressString(compressed); + if (!str.equals(uncompressed)) { + throw new IllegalStateException("String roundtrip failed"); + } }); - + runFuzz(() -> { - int maxLen = Snappy.maxCompressedLength(input.length); + int len = data.consumeInt(0, 4096); + int maxLen = Snappy.maxCompressedLength(len); + if (maxLen < len) { + throw new IllegalStateException("maxCompressedLength too small"); + } }); - + runFuzz(() -> { - short[] shortInput = new short[Math.min(100, input.length / 2)]; - for (int i = 0; i < shortInput.length; i++) { - shortInput[i] = (short) data.consumeInt(); - } + short[] shortInput = data.consumeShorts(data.consumeInt(0, 100)); byte[] compressedShorts = Snappy.compress(shortInput); short[] uncompressedShorts = Snappy.uncompressShortArray(compressedShorts); + if (!Arrays.equals(shortInput, uncompressedShorts)) { + throw new IllegalStateException("Short array roundtrip failed"); + } }); - + runFuzz(() -> { - char[] charInput = new char[Math.min(100, input.length)]; - for (int i = 0; i < charInput.length; i++) { - charInput[i] = (char) data.consumeInt(); - } + char[] charInput = data.consumeString(data.consumeInt(0, 100)).toCharArray(); byte[] compressedChars = Snappy.compress(charInput); char[] uncompressedChars = Snappy.uncompressCharArray(compressedChars); + if (!Arrays.equals(charInput, uncompressedChars)) { + throw new IllegalStateException("Char array roundtrip failed"); + } }); } private static void testBitShuffle(FuzzedDataProvider data) { runFuzz(() -> { - int[] intInput = data.consumeInts(100); + int[] intInput = data.consumeInts(data.consumeInt(0, 100)); byte[] shuffled = BitShuffle.shuffle(intInput); int[] unshuffled = BitShuffle.unshuffleIntArray(shuffled); if (!Arrays.equals(intInput, unshuffled)) { @@ -273,7 +302,7 @@ private static void testBitShuffle(FuzzedDataProvider data) { }); runFuzz(() -> { - long[] longInput = data.consumeLongs(50); + long[] longInput = data.consumeLongs(data.consumeInt(0, 50)); byte[] shuffled = BitShuffle.shuffle(longInput); long[] unshuffled = BitShuffle.unshuffleLongArray(shuffled); if (!Arrays.equals(longInput, unshuffled)) { @@ -282,7 +311,7 @@ private static void testBitShuffle(FuzzedDataProvider data) { }); runFuzz(() -> { - short[] shortInput = data.consumeShorts(100); + short[] shortInput = data.consumeShorts(data.consumeInt(0, 100)); byte[] shuffled = BitShuffle.shuffle(shortInput); short[] unshuffled = BitShuffle.unshuffleShortArray(shuffled); if (!Arrays.equals(shortInput, unshuffled)) { @@ -292,15 +321,14 @@ private static void testBitShuffle(FuzzedDataProvider data) { } private static void testHadoopStream(FuzzedDataProvider data) { - byte[] original = data.consumeRemainingAsBytes(); - runFuzz(() -> { + byte[] original = data.consumeBytes(data.consumeInt(0, 4096)); ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); SnappyHadoopCompatibleOutputStream out = new SnappyHadoopCompatibleOutputStream(compressedBuf); out.write(original); out.close(); byte[] compressed = compressedBuf.toByteArray(); - + try (SnappyInputStream in = new SnappyInputStream( new ByteArrayInputStream(compressed))) { ByteArrayOutputStream result = new ByteArrayOutputStream(); @@ -309,14 +337,16 @@ private static void testHadoopStream(FuzzedDataProvider data) { while ((read = in.read(buf)) != -1) { result.write(buf, 0, read); } + if (!Arrays.equals(original, result.toByteArray())) { + throw new IllegalStateException("Hadoop stream roundtrip failed"); + } } }); } private static void testByteBuffer(FuzzedDataProvider data) { - byte[] input = data.consumeRemainingAsBytes(); - runFuzz(() -> { + byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); ByteBuffer src = ByteBuffer.allocateDirect(input.length); src.put(input); src.flip(); @@ -339,6 +369,7 @@ private static void testByteBuffer(FuzzedDataProvider data) { }); runFuzz(() -> { + byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); ByteBuffer directSrc = ByteBuffer.allocateDirect(input.length); directSrc.put(input); directSrc.flip(); From 363eb19b05d3fd56c54d25f8e150adfaf4113e13 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 10:05:51 +0530 Subject: [PATCH 17/23] - --- .../xerial/snappy/fuzz/BitShuffleFuzzer.java | 67 +++++++++---------- .../snappy/fuzz/SnappyCombinedFuzzer.java | 23 ++++--- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index eedd5ed1..6bb3fdb6 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -19,7 +19,6 @@ import com.code_intelligence.jazzer.api.FuzzedDataProvider; import org.xerial.snappy.Snappy; import org.xerial.snappy.BitShuffle; -import java.io.IOException; import java.util.Arrays; public class BitShuffleFuzzer { @@ -31,54 +30,52 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { fuzzBitshuffleShorts(data.consumeShorts(SIZE)); } - static void fuzzBitshuffleInts(int[] original) { - int[] result; - + private static void runFuzz(RunnableWithException block) { try { - byte[] shuffledByteArray = BitShuffle.shuffle(original); - byte[] compressed = Snappy.compress(shuffledByteArray); - byte[] uncompressed = Snappy.uncompress(compressed); - result = BitShuffle.unshuffleIntArray(uncompressed); - } catch (IOException e) { + block.run(); + } catch (Exception e) { throw new RuntimeException(e); } - - if (!Arrays.equals(original, result)) { - throw new IllegalStateException("Original and uncompressed data are different"); - } } - static void fuzzBitshuffleLongs(long[] original) { - long[] result; + @FunctionalInterface + private interface RunnableWithException { + void run() throws Exception; + } - try { + private static void fuzzBitshuffleInts(int[] original) { + runFuzz(() -> { byte[] shuffledByteArray = BitShuffle.shuffle(original); byte[] compressed = Snappy.compress(shuffledByteArray); byte[] uncompressed = Snappy.uncompress(compressed); - result = BitShuffle.unshuffleLongArray(uncompressed); - } catch (IOException e) { - throw new RuntimeException(e); - } - - if (!Arrays.equals(original, result)) { - throw new IllegalStateException("Original and uncompressed data are different"); - } + int[] result = BitShuffle.unshuffleIntArray(uncompressed); + if (!Arrays.equals(original, result)) { + throw new IllegalStateException("Original and uncompressed data are different"); + } + }); } - static void fuzzBitshuffleShorts(short[] original) { - short[] result; - - try { + private static void fuzzBitshuffleLongs(long[] original) { + runFuzz(() -> { byte[] shuffledByteArray = BitShuffle.shuffle(original); byte[] compressed = Snappy.compress(shuffledByteArray); byte[] uncompressed = Snappy.uncompress(compressed); - result = BitShuffle.unshuffleShortArray(uncompressed); - } catch (IOException e) { - throw new RuntimeException(e); - } + long[] result = BitShuffle.unshuffleLongArray(uncompressed); + if (!Arrays.equals(original, result)) { + throw new IllegalStateException("Original and uncompressed data are different"); + } + }); + } - 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"); + } + }); } } diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 347eb562..348009bb 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -200,14 +200,25 @@ private static void testCrc32C(FuzzedDataProvider data) { for (int i = 0; i < Math.min(input.length, 1000); i++) { crcChunked.update(input[i] & 0xFF); } + long chunkedValue = crcChunked.getValue(); + + PureJavaCrc32C crcWhole = new PureJavaCrc32C(); + crcWhole.update(input, 0, input.length); + long wholeValue = crcWhole.getValue(); + + if (input.length <= 1000 && chunkedValue != wholeValue) { + throw new IllegalStateException("CRC32C chunked vs whole mismatch"); + } if (chunk1.length > 0 && chunk2.length > 0) { PureJavaCrc32C crc1 = new PureJavaCrc32C(); crc1.update(input, 0, input.length); + long crc1Value = crc1.getValue(); PureJavaCrc32C crc2 = new PureJavaCrc32C(); crc2.update(chunk1, 0, chunk1.length); crc2.update(chunk2, 0, chunk2.length); + long crc2Value = crc2.getValue(); } PureJavaCrc32C crcEmpty = new PureJavaCrc32C(); @@ -217,11 +228,13 @@ private static void testCrc32C(FuzzedDataProvider data) { if (input.length > 0) { PureJavaCrc32C crcSingle = new PureJavaCrc32C(); crcSingle.update(input[0] & 0xFF); + long singleValue = crcSingle.getValue(); } if (input.length > 4) { PureJavaCrc32C crcOffset = new PureJavaCrc32C(); crcOffset.update(input, 1, input.length - 1); + long offsetValue = crcOffset.getValue(); } } @@ -367,15 +380,5 @@ private static void testByteBuffer(FuzzedDataProvider data) { throw new IllegalStateException("ByteBuffer compress failed"); } }); - - runFuzz(() -> { - byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); - ByteBuffer directSrc = ByteBuffer.allocateDirect(input.length); - directSrc.put(input); - directSrc.flip(); - - ByteBuffer directDst = ByteBuffer.allocateDirect(Snappy.maxCompressedLength(input.length)); - Snappy.compress(directSrc, directDst); - }); } } From cf0ca819bbe11c53a3afe09d25a6e8a788bc62f2 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 10:42:48 +0530 Subject: [PATCH 18/23] - --- .../snappy/fuzz/SnappyCombinedFuzzer.java | 36 +++---------------- .../snappy/fuzz/SnappyStreamFuzzer.java | 10 +++--- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 348009bb..4eb4c0d7 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -33,6 +33,7 @@ public class SnappyCombinedFuzzer { + @FunctionalInterface private interface FuzzBlock { void run() throws Exception; } @@ -180,14 +181,15 @@ private static void testFramed(FuzzedDataProvider data) { private static void testCrc32C(FuzzedDataProvider data) { byte[] input = data.consumeBytes(data.consumeInt(0, 4096)); - byte[] chunk1 = data.consumeBytes(50); - byte[] chunk2 = data.consumeBytes(50); PureJavaCrc32C crc = new PureJavaCrc32C(); crc.update(input, 0, input.length); long value = crc.getValue(); int intValue = crc.getIntegerValue(); + if ((int) value != intValue) { + throw new IllegalStateException("CRC32C int value mismatch"); + } crc.reset(); crc.update(input, 0, input.length); @@ -200,42 +202,14 @@ private static void testCrc32C(FuzzedDataProvider data) { for (int i = 0; i < Math.min(input.length, 1000); i++) { crcChunked.update(input[i] & 0xFF); } - long chunkedValue = crcChunked.getValue(); PureJavaCrc32C crcWhole = new PureJavaCrc32C(); crcWhole.update(input, 0, input.length); long wholeValue = crcWhole.getValue(); - if (input.length <= 1000 && chunkedValue != wholeValue) { + if (input.length <= 1000 && crcChunked.getValue() != wholeValue) { throw new IllegalStateException("CRC32C chunked vs whole mismatch"); } - - if (chunk1.length > 0 && chunk2.length > 0) { - PureJavaCrc32C crc1 = new PureJavaCrc32C(); - crc1.update(input, 0, input.length); - long crc1Value = crc1.getValue(); - - PureJavaCrc32C crc2 = new PureJavaCrc32C(); - crc2.update(chunk1, 0, chunk1.length); - crc2.update(chunk2, 0, chunk2.length); - long crc2Value = crc2.getValue(); - } - - PureJavaCrc32C crcEmpty = new PureJavaCrc32C(); - crcEmpty.update(new byte[0], 0, 0); - long emptyValue = crcEmpty.getValue(); - - if (input.length > 0) { - PureJavaCrc32C crcSingle = new PureJavaCrc32C(); - crcSingle.update(input[0] & 0xFF); - long singleValue = crcSingle.getValue(); - } - - if (input.length > 4) { - PureJavaCrc32C crcOffset = new PureJavaCrc32C(); - crcOffset.update(input, 1, input.length - 1); - long offsetValue = crcOffset.getValue(); - } } private static void testBlockStream(FuzzedDataProvider data) { diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index 1b5110c5..095d29d2 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -28,7 +28,6 @@ public class SnappyStreamFuzzer { public static void fuzzerTestOneInput(FuzzedDataProvider data) { byte[] original = data.consumeRemainingAsBytes(); - byte[] uncompressed = null; try { ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); @@ -37,6 +36,7 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { snappyOut.close(); byte[] compressed = compressedBuf.toByteArray(); + byte[] uncompressed; try (SnappyInputStream snappyIn = new SnappyInputStream(new ByteArrayInputStream(compressed))) { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; @@ -47,12 +47,12 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { out.flush(); uncompressed = out.toByteArray(); } + + if (!Arrays.equals(original, uncompressed)) { + throw new IllegalStateException("Original and uncompressed data are different"); + } } catch (IOException e) { throw new RuntimeException(e); - } - - if (!Arrays.equals(original, uncompressed)) { - throw new IllegalStateException("Original and uncompressed data are different"); } } } From 4fb7af69e79c99107f25dc997cc586042a52981d Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 10:48:42 +0530 Subject: [PATCH 19/23] - --- .../snappy/fuzz/SnappyStreamFuzzer.java | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index 095d29d2..f4b48dbd 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -24,35 +24,50 @@ import java.io.ByteArrayOutputStream; import java.util.Arrays; +/** + * Fuzzer for Snappy's block-based stream format, as implemented by + * {@link SnappyOutputStream} and {@link SnappyInputStream}. + * This is different from the "x-snappy-framed" format. + */ public class SnappyStreamFuzzer { - public static void fuzzerTestOneInput(FuzzedDataProvider data) { - - byte[] original = data.consumeRemainingAsBytes(); - try { - ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); - SnappyOutputStream snappyOut = new SnappyOutputStream(compressedBuf); - snappyOut.write(original); - snappyOut.close(); - byte[] compressed = compressedBuf.toByteArray(); - - byte[] uncompressed; - try (SnappyInputStream snappyIn = new SnappyInputStream(new ByteArrayInputStream(compressed))) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buf = new byte[4096]; - int readBytes; - while ((readBytes = snappyIn.read(buf)) != -1) { - out.write(buf, 0, readBytes); + @FunctionalInterface + private interface FuzzBlock { + void run() throws Exception; + } + + private static void runFuzz(FuzzBlock block) { + try { + block.run(); + } catch (Exception e) { + throw new RuntimeException(e); } - out.flush(); - uncompressed = out.toByteArray(); - } + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + byte[] original = data.consumeRemainingAsBytes(); + + runFuzz(() -> { + ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); + try (SnappyOutputStream snappyOut = new SnappyOutputStream(compressedBuf)) { + snappyOut.write(original); + } + byte[] compressed = compressedBuf.toByteArray(); + + byte[] uncompressed; + try (SnappyInputStream snappyIn = new SnappyInputStream(new ByteArrayInputStream(compressed))) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[4096]; + int readBytes; + while ((readBytes = snappyIn.read(buf)) != -1) { + out.write(buf, 0, readBytes); + } + uncompressed = out.toByteArray(); + } - if (!Arrays.equals(original, uncompressed)) { - throw new IllegalStateException("Original and uncompressed data are different"); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } + if (!Arrays.equals(original, uncompressed)) { + throw new IllegalStateException("Original and uncompressed data are different"); + } + }); + } } From 528015f719cc604053977efe94265af00091db40 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 10:58:50 +0530 Subject: [PATCH 20/23] - --- .../xerial/snappy/fuzz/BitShuffleFuzzer.java | 59 +++++++------------ .../org/xerial/snappy/fuzz/FuzzBlock.java | 22 +++++++ .../snappy/fuzz/SnappyCombinedFuzzer.java | 10 +--- .../snappy/fuzz/SnappyStreamFuzzer.java | 5 -- 4 files changed, 44 insertions(+), 52 deletions(-) create mode 100644 src/test/java/org/xerial/snappy/fuzz/FuzzBlock.java diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index 6bb3fdb6..a4e67be5 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -20,62 +20,43 @@ import org.xerial.snappy.Snappy; import org.xerial.snappy.BitShuffle; import java.util.Arrays; +import java.util.function.Function; 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)); - } - - private static void runFuzz(RunnableWithException block) { - try { - block.run(); - } catch (Exception e) { - throw new RuntimeException(e); - } + fuzzBitshuffle(data.consumeInts(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleIntArray, "int[]"); + fuzzBitshuffle(data.consumeLongs(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleLongArray, "long[]"); + fuzzBitshuffle(data.consumeShorts(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleShortArray, "short[]"); } @FunctionalInterface - private interface RunnableWithException { + private interface ExceptionRunnable { void run() throws Exception; } - 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"); - } - }); + @FunctionalInterface + private interface ShuffleFn { + byte[] apply(T input) throws Exception; } - 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"); - } - }); + @FunctionalInterface + private interface UnshuffleFn { + T apply(byte[] input) throws Exception; } - private static void fuzzBitshuffleShorts(short[] original) { - runFuzz(() -> { - byte[] shuffledByteArray = BitShuffle.shuffle(original); + private static void fuzzBitshuffle(T original, ShuffleFn shuffle, UnshuffleFn unshuffle, String typeName) { + try { + byte[] shuffledByteArray = shuffle.apply(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"); + T result = unshuffle.apply(uncompressed); + if (!Arrays.equals((Object[]) original, (Object[]) result)) { + throw new IllegalStateException("Original and uncompressed " + typeName + " data are different"); } - }); + } catch (Exception e) { + throw new RuntimeException(e); + } } } diff --git a/src/test/java/org/xerial/snappy/fuzz/FuzzBlock.java b/src/test/java/org/xerial/snappy/fuzz/FuzzBlock.java new file mode 100644 index 00000000..c3228f94 --- /dev/null +++ b/src/test/java/org/xerial/snappy/fuzz/FuzzBlock.java @@ -0,0 +1,22 @@ +// 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; + +@FunctionalInterface +public interface FuzzBlock { + void run() throws Exception; +} diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 4eb4c0d7..0e71fa48 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -33,11 +33,6 @@ public class SnappyCombinedFuzzer { - @FunctionalInterface - private interface FuzzBlock { - void run() throws Exception; - } - private static void runFuzz(FuzzBlock block) { try { block.run(); @@ -199,15 +194,14 @@ private static void testCrc32C(FuzzedDataProvider data) { } PureJavaCrc32C crcChunked = new PureJavaCrc32C(); - for (int i = 0; i < Math.min(input.length, 1000); i++) { + for (int i = 0; i < input.length; i++) { crcChunked.update(input[i] & 0xFF); } PureJavaCrc32C crcWhole = new PureJavaCrc32C(); crcWhole.update(input, 0, input.length); - long wholeValue = crcWhole.getValue(); - if (input.length <= 1000 && crcChunked.getValue() != wholeValue) { + if (crcChunked.getValue() != crcWhole.getValue()) { throw new IllegalStateException("CRC32C chunked vs whole mismatch"); } } diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index f4b48dbd..c121c3f9 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -31,11 +31,6 @@ */ public class SnappyStreamFuzzer { - @FunctionalInterface - private interface FuzzBlock { - void run() throws Exception; - } - private static void runFuzz(FuzzBlock block) { try { block.run(); From ff76e20216841037ccc17fe91ed95e9505cc1972 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 11:08:50 +0530 Subject: [PATCH 21/23] - --- .../java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java | 10 ++-------- .../org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java | 1 - .../org/xerial/snappy/fuzz/SnappyStreamFuzzer.java | 1 - 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index a4e67be5..fa43bb4c 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -19,8 +19,7 @@ import com.code_intelligence.jazzer.api.FuzzedDataProvider; import org.xerial.snappy.Snappy; import org.xerial.snappy.BitShuffle; -import java.util.Arrays; -import java.util.function.Function; +import java.util.Objects; public class BitShuffleFuzzer { private static final int SIZE = 4096; @@ -31,11 +30,6 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { fuzzBitshuffle(data.consumeShorts(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleShortArray, "short[]"); } - @FunctionalInterface - private interface ExceptionRunnable { - void run() throws Exception; - } - @FunctionalInterface private interface ShuffleFn { byte[] apply(T input) throws Exception; @@ -52,7 +46,7 @@ private static void fuzzBitshuffle(T original, ShuffleFn shuffle, Unshuff byte[] compressed = Snappy.compress(shuffledByteArray); byte[] uncompressed = Snappy.uncompress(compressed); T result = unshuffle.apply(uncompressed); - if (!Arrays.equals((Object[]) original, (Object[]) result)) { + if (!Objects.deepEquals(original, result)) { throw new IllegalStateException("Original and uncompressed " + typeName + " data are different"); } } catch (Exception e) { diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 0e71fa48..80b4196d 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -28,7 +28,6 @@ import java.nio.ByteBuffer; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.util.Arrays; public class SnappyCombinedFuzzer { diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java index c121c3f9..dbbabeba 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyStreamFuzzer.java @@ -19,7 +19,6 @@ import com.code_intelligence.jazzer.api.FuzzedDataProvider; import org.xerial.snappy.SnappyInputStream; import org.xerial.snappy.SnappyOutputStream; -import java.io.IOException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Arrays; From 4640f7ba86dd26cdb6e61ab8be6fb07ad736bf7f Mon Sep 17 00:00:00 2001 From: Vishal S <130894175+vishalcoc44@users.noreply.github.com> Date: Sat, 14 Mar 2026 11:15:02 +0530 Subject: [PATCH 22/23] Update src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java index 80b4196d..3617b5bd 100644 --- a/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/SnappyCombinedFuzzer.java @@ -209,7 +209,7 @@ private static void testBlockStream(FuzzedDataProvider data) { runFuzz(() -> { byte[] original = data.consumeBytes(data.consumeInt(0, 4096)); ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream(); - SnappyOutputStream out = new SnappyOutputStream(compressedBuf, -1); + SnappyOutputStream out = new SnappyOutputStream(compressedBuf, SnappyOutputStream.MIN_BLOCK_SIZE); out.write(original); out.close(); byte[] compressed = compressedBuf.toByteArray(); From b0566b6f3884bf4e192883b91ee21824b074d837 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Sat, 14 Mar 2026 11:37:48 +0530 Subject: [PATCH 23/23] - --- src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java index fa43bb4c..67de614c 100644 --- a/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java +++ b/src/test/java/org/xerial/snappy/fuzz/BitShuffleFuzzer.java @@ -28,6 +28,8 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { fuzzBitshuffle(data.consumeInts(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleIntArray, "int[]"); fuzzBitshuffle(data.consumeLongs(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleLongArray, "long[]"); fuzzBitshuffle(data.consumeShorts(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleShortArray, "short[]"); + fuzzBitshuffle(data.consumeFloats(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleFloatArray, "float[]"); + fuzzBitshuffle(data.consumeDoubles(SIZE), BitShuffle::shuffle, BitShuffle::unshuffleDoubleArray, "double[]"); } @FunctionalInterface