brotli-java: initial integration (#6786)

* brotli-java: initial integration

* update engine and sanitizer for java project

* tni

* brotli-java: update yaml and remove unused variable
This commit is contained in:
DavidKorczynski 2021-11-23 15:44:02 +00:00 committed by GitHub
parent 93653634e9
commit 299221cad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,27 @@
# 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-jvm
RUN apt-get update && apt-get install -y make autoconf automake libtool wget
RUN curl -L https://downloads.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.zip -o maven.zip && \
unzip maven.zip -d $SRC/maven && \
rm -rf maven.zip
ENV MVN $SRC/maven/apache-maven-3.8.3/bin/mvn
RUN git clone --depth 1 https://github.com/google/brotli brotli-java
WORKDIR brotli-java
COPY build.sh $SRC/
COPY *.java $SRC/

View File

@ -0,0 +1,36 @@
// 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 com.code_intelligence.jazzer.api.FuzzedDataProvider;
import java.io.*;
import org.brotli.dec.BrotliInputStream;
public class FuzzDecode {
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
byte[] buffer = new byte[65536];
ByteArrayInputStream input = new ByteArrayInputStream(data.consumeBytes(65536));
try {
BrotliInputStream brotliInput = new BrotliInputStream(input);
while (true) {
int len = brotliInput.read(buffer, 0, buffer.length);
if (len <= 0) {
break;
}
}
} catch (IOException expected) {}
}
}

45
projects/brotli-java/build.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash -eu
# 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.
#
################################################################################
cd java/org/brotli
sed -i 's/1.6</1.7</g' ./pom.xml
MAVEN_ARGS="-Dmaven.test.skip=true -Djavac.src.version=11 -Djavac.target.version=11 -X"
$MVN package
find ./dec -name "dec-*.jar" -exec mv {} $OUT/dec.jar \;
ALL_JARS="dec.jar"
BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH
RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):.:\$this_dir
for fuzzer in $(find $SRC -name 'Fuzz*.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

View File

@ -0,0 +1,10 @@
homepage: "https://github.com/google/brotli/tree/master/java"
language: jvm
primary_contact: "eustas@chromium.org"
main_repo: "https://github.com/google/brotli"
auto_ccs:
- "david@adalogics.com"
fuzzing_engines:
- libfuzzer
sanitizers:
- address