diff options
author | 2021-04-19 17:12:46 +0200 | |
---|---|---|
committer | 2021-04-19 08:12:46 -0700 | |
commit | 17db8249e084dd54cb839e2560dab3c0c9a31b7b (patch) | |
tree | e25fad2ed32f1311c04d4c634e06575c4b6f3cc5 /projects/apache-commons | |
parent | 1336f9e42eeb1afc908310a6a6baaf2a5e9469b8 (diff) |
[apache-commons] Initial integration (#5633)
Adds fuzzers for Imaging and Compress.
Diffstat (limited to 'projects/apache-commons')
-rw-r--r-- | projects/apache-commons/CompressSevenZFuzzer.java | 39 | ||||
-rw-r--r-- | projects/apache-commons/CompressTarFuzzer.java | 33 | ||||
-rw-r--r-- | projects/apache-commons/CompressZipFuzzer.java | 34 | ||||
-rw-r--r-- | projects/apache-commons/Dockerfile | 58 | ||||
-rw-r--r-- | projects/apache-commons/ImagingBmpFuzzer.java | 30 | ||||
-rw-r--r-- | projects/apache-commons/ImagingGifFuzzer.java | 30 | ||||
-rw-r--r-- | projects/apache-commons/ImagingJpegFuzzer.java | 30 | ||||
-rw-r--r-- | projects/apache-commons/ImagingPngFuzzer.java | 30 | ||||
-rw-r--r-- | projects/apache-commons/ImagingTiffFuzzer.java | 30 | ||||
-rwxr-xr-x | projects/apache-commons/build.sh | 57 | ||||
-rw-r--r-- | projects/apache-commons/project.yaml | 13 |
11 files changed, 384 insertions, 0 deletions
diff --git a/projects/apache-commons/CompressSevenZFuzzer.java b/projects/apache-commons/CompressSevenZFuzzer.java new file mode 100644 index 00000000..8bc19321 --- /dev/null +++ b/projects/apache-commons/CompressSevenZFuzzer.java @@ -0,0 +1,39 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import org.apache.commons.compress.archivers.sevenz.SevenZFile; +import org.apache.commons.compress.archivers.sevenz.SevenZFileOptions; +import org.apache.commons.compress.utils.SeekableInMemoryByteChannel; + +import java.io.IOException; +import java.util.logging.LogManager; + +public class CompressSevenZFuzzer { + private static final SevenZFileOptions options = new SevenZFileOptions.Builder() + .withMaxMemoryLimitInKb(1_000_000) + .build(); + + public static void fuzzerInitialize() { + LogManager.getLogManager().reset(); + } + + public static void fuzzerTestOneInput(byte[] data) { + try { + new SevenZFile(new SeekableInMemoryByteChannel(data), options).close(); + } catch (IOException ignored) { + } + } +} diff --git a/projects/apache-commons/CompressTarFuzzer.java b/projects/apache-commons/CompressTarFuzzer.java new file mode 100644 index 00000000..2df863df --- /dev/null +++ b/projects/apache-commons/CompressTarFuzzer.java @@ -0,0 +1,33 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import org.apache.commons.compress.archivers.tar.TarFile; + +import java.io.IOException; +import java.util.logging.LogManager; + +public class CompressTarFuzzer { + public static void fuzzerInitialize() { + LogManager.getLogManager().reset(); + } + + public static void fuzzerTestOneInput(byte[] data) { + try { + new TarFile(data).close(); + } catch (IOException ignored) { + } + } +} diff --git a/projects/apache-commons/CompressZipFuzzer.java b/projects/apache-commons/CompressZipFuzzer.java new file mode 100644 index 00000000..bc9a8a0e --- /dev/null +++ b/projects/apache-commons/CompressZipFuzzer.java @@ -0,0 +1,34 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.commons.compress.utils.SeekableInMemoryByteChannel; + +import java.io.IOException; +import java.util.logging.LogManager; + +public class CompressZipFuzzer { + public static void fuzzerInitialize() { + LogManager.getLogManager().reset(); + } + + public static void fuzzerTestOneInput(byte[] data) { + try { + new ZipFile(new SeekableInMemoryByteChannel(data)).close(); + } catch (IOException ignored) { + } + } +} diff --git a/projects/apache-commons/Dockerfile b/projects/apache-commons/Dockerfile new file mode 100644 index 00000000..c9462101 --- /dev/null +++ b/projects/apache-commons/Dockerfile @@ -0,0 +1,58 @@ +# Copyright 2021 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. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder + +RUN curl -L https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip -o maven.zip && \ + unzip maven.zip -d $SRC/maven && \ + rm -rf maven.zip + +ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn + +# Dictionaries +RUN git clone --depth 1 https://github.com/google/fuzzing && \ + mv fuzzing/dictionaries/zip.dict $SRC/CompressZipFuzzer.dict && \ + mv fuzzing/dictionaries/gif.dict $SRC/ImagingGifFuzzer.dict && \ + mv fuzzing/dictionaries/jpeg.dict $SRC/ImagingJpegFuzzer.dict && \ + mv fuzzing/dictionaries/png.dict $SRC/ImagingPngFuzzer.dict && \ + mv fuzzing/dictionaries/tiff.dict $SRC/ImagingTiffFuzzer.dict && \ + rm -rf fuzzing + +# Seed corpus (go-fuzz-corpus) +RUN git clone --depth 1 https://github.com/dvyukov/go-fuzz-corpus && \ + zip -j $SRC/CompressTarFuzzer_seed_corpus.zip go-fuzz-corpus/tar/corpus/* && \ + zip -j $SRC/CompressZipFuzzer_seed_corpus.zip go-fuzz-corpus/zip/corpus/* && \ + zip -j $SRC/ImagingBmpFuzzer_seed_corpus.zip go-fuzz-corpus/bmp/corpus/* && \ + zip -j $SRC/ImagingGifFuzzer_seed_corpus.zip go-fuzz-corpus/gif/corpus/* && \ + zip -j $SRC/ImagingJpegFuzzer_seed_corpus.zip go-fuzz-corpus/jpeg/corpus/* && \ + zip -j $SRC/ImagingPngFuzzer_seed_corpus.zip go-fuzz-corpus/png/corpus/* && \ + zip -j $SRC/ImagingTiffFuzzer_seed_corpus.zip go-fuzz-corpus/tiff/corpus/* && \ + rm -rf go-fuzz-corpus + +# Compress +RUN git clone --depth 1 https://gitbox.apache.org/repos/asf/commons-compress.git + +RUN zip -uj $SRC/CompressTarFuzzer_seed_corpus.zip commons-compress/src/test/resources/*.tar && \ + zip -uj $SRC/CompressZipFuzzer_seed_corpus.zip commons-compress/src/test/resources/*.zip && \ + zip -j $SRC/CompressSevenZFuzzer_seed_corpus.zip commons-compress/src/test/resources/bla.7z + +# Imaging +RUN git clone --depth 1 https://gitbox.apache.org/repos/asf/commons-imaging.git + +# Copy build script and all fuzzers +COPY build.sh $SRC/ +COPY *Fuzzer.java $SRC/ +WORKDIR $SRC/ diff --git a/projects/apache-commons/ImagingBmpFuzzer.java b/projects/apache-commons/ImagingBmpFuzzer.java new file mode 100644 index 00000000..c9071705 --- /dev/null +++ b/projects/apache-commons/ImagingBmpFuzzer.java @@ -0,0 +1,30 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import java.io.IOException; +import java.util.HashMap; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.common.bytesource.ByteSourceArray; +import org.apache.commons.imaging.formats.bmp.BmpImageParser; + +public class ImagingBmpFuzzer { + public static void fuzzerTestOneInput(byte[] input) { + try { + new BmpImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>()); + } catch (IOException | ImageReadException ignored) { + } + } +} diff --git a/projects/apache-commons/ImagingGifFuzzer.java b/projects/apache-commons/ImagingGifFuzzer.java new file mode 100644 index 00000000..6c59cf42 --- /dev/null +++ b/projects/apache-commons/ImagingGifFuzzer.java @@ -0,0 +1,30 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import java.io.IOException; +import java.util.HashMap; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.common.bytesource.ByteSourceArray; +import org.apache.commons.imaging.formats.gif.GifImageParser; + +public class ImagingGifFuzzer { + public static void fuzzerTestOneInput(byte[] input) { + try { + new GifImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>()); + } catch (IOException | ImageReadException ignored) { + } + } +} diff --git a/projects/apache-commons/ImagingJpegFuzzer.java b/projects/apache-commons/ImagingJpegFuzzer.java new file mode 100644 index 00000000..a40004e7 --- /dev/null +++ b/projects/apache-commons/ImagingJpegFuzzer.java @@ -0,0 +1,30 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import java.io.IOException; +import java.util.HashMap; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.common.bytesource.ByteSourceArray; +import org.apache.commons.imaging.formats.jpeg.JpegImageParser; + +public class ImagingJpegFuzzer { + public static void fuzzerTestOneInput(byte[] input) { + try { + new JpegImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>()); + } catch (IOException | ImageReadException ignored) { + } + } +} diff --git a/projects/apache-commons/ImagingPngFuzzer.java b/projects/apache-commons/ImagingPngFuzzer.java new file mode 100644 index 00000000..406480dd --- /dev/null +++ b/projects/apache-commons/ImagingPngFuzzer.java @@ -0,0 +1,30 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import java.io.IOException; +import java.util.HashMap; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.common.bytesource.ByteSourceArray; +import org.apache.commons.imaging.formats.png.PngImageParser; + +public class ImagingPngFuzzer { + public static void fuzzerTestOneInput(byte[] input) { + try { + new PngImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>()); + } catch (IOException | ImageReadException ignored) { + } + } +} diff --git a/projects/apache-commons/ImagingTiffFuzzer.java b/projects/apache-commons/ImagingTiffFuzzer.java new file mode 100644 index 00000000..68337519 --- /dev/null +++ b/projects/apache-commons/ImagingTiffFuzzer.java @@ -0,0 +1,30 @@ +// Copyright 2021 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. +// +//////////////////////////////////////////////////////////////////////////////// + +import java.io.IOException; +import java.util.HashMap; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.common.bytesource.ByteSourceArray; +import org.apache.commons.imaging.formats.tiff.TiffImageParser; + +public class ImagingTiffFuzzer { + public static void fuzzerTestOneInput(byte[] input) { + try { + new TiffImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>()); + } catch (IOException | ImageReadException ignored) { + } + } +} diff --git a/projects/apache-commons/build.sh b/projects/apache-commons/build.sh new file mode 100755 index 00000000..fa888f30 --- /dev/null +++ b/projects/apache-commons/build.sh @@ -0,0 +1,57 @@ +#!/bin/bash -eu +# Copyright 2021 Google Inc. +# +# 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. +# +################################################################################ + +# Move seed corpus and dictionary. +mv $SRC/{*.zip,*.dict} $OUT + +PROJECTS="compress imaging" + +for project in $PROJECTS; do + cd $SRC/commons-$project + MAVEN_ARGS="-Dmaven.test.skip=true -Djavac.src.version=15 -Djavac.target.version=15 -Djdk.version=15" + $MVN package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade $MAVEN_ARGS + CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \ + -Dexpression=project.version -q -DforceStdout) + cp "target/commons-$project-$CURRENT_VERSION.jar" $OUT/commons-$project.jar + + ALL_JARS="commons-$project.jar" + + # The classpath at build-time includes the project jars in $OUT as well as the + # Jazzer API. + BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH + + # All .jar and .class files lie in the same directory as the fuzzer at runtime. + RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir + + for fuzzer in $(find $SRC -iname "$project"'*Fuzzer.java'); do + fuzzer_basename=$(basename -s .java $fuzzer) + javac -cp $BUILD_CLASSPATH $fuzzer + cp $SRC/$fuzzer_basename.class $OUT/ + + # Create an execution wrapper that executes Jazzer with the correct arguments. + echo "#!/bin/sh +# LLVMFuzzerTestOneInput for fuzzer detection. +this_dir=\$(dirname \"\$0\") +LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \ +\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \ +--cp=$RUNTIME_CLASSPATH \ +--target_class=$fuzzer_basename \ +--jvm_args=\"-Xmx2048m\" \ +\$@" > $OUT/$fuzzer_basename + chmod u+x $OUT/$fuzzer_basename + done +done diff --git a/projects/apache-commons/project.yaml b/projects/apache-commons/project.yaml new file mode 100644 index 00000000..3a805c14 --- /dev/null +++ b/projects/apache-commons/project.yaml @@ -0,0 +1,13 @@ +homepage: "https://commons.apache.org" +language: jvm +primary_contact: "bodewig@apache.org" +auto_ccs: + - "fuzz-testing@commons.apache.org" + - "boards@gmail.com" + - "brunodepaulak@gmail.com" + - "meumertzheim@code-intelligence.com" +fuzzing_engines: + - libfuzzer +main_repo: "https://gitbox.apache.org/repos/asf/commons-compress.git" +sanitizers: + - address |