diff --git a/projects/gson/Dockerfile b/projects/gson/Dockerfile new file mode 100644 index 000000000..3dffa2ccd --- /dev/null +++ b/projects/gson/Dockerfile @@ -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. +# +################################################################################ + +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/gson gson +WORKDIR gson +COPY build.sh $SRC/ +COPY pom.xml $SRC/gson/pom.xml +COPY gson/pom.xml $SRC/gson/gson/pom.xml +COPY *.java $SRC/ diff --git a/projects/gson/FuzzParse.java b/projects/gson/FuzzParse.java new file mode 100644 index 000000000..6fe85e1ce --- /dev/null +++ b/projects/gson/FuzzParse.java @@ -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. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; + +import java.io.*; +import com.google.gson.*; + +public class FuzzParse { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + JsonParser.parseString(data.consumeRemainingAsString()); + } catch (JsonSyntaxException expected) { } + } +} diff --git a/projects/gson/FuzzReader.java b/projects/gson/FuzzReader.java new file mode 100644 index 000000000..7566a976c --- /dev/null +++ b/projects/gson/FuzzReader.java @@ -0,0 +1,35 @@ +// 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 com.google.gson.*; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; + +public class FuzzReader { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + TypeAdapter adapter = new Gson().getAdapter(JsonElement.class); + boolean lenient = data.consumeBoolean(); + JsonReader reader = new JsonReader(new StringReader(data.consumeRemainingAsString())); + reader.setLenient(lenient); + try { + while (reader.peek() != JsonToken.END_DOCUMENT) { + adapter.read(reader); + } + } catch (JsonSyntaxException | IOException expected) { } + } +} diff --git a/projects/gson/build.sh b/projects/gson/build.sh new file mode 100755 index 000000000..5de2d1fc7 --- /dev/null +++ b/projects/gson/build.sh @@ -0,0 +1,42 @@ +#!/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. +# +################################################################################ + +MAVEN_ARGS="-Dmaven.test.skip=true -Djavac.src.version=11 -Djavac.target.version=11 -X" +$MVN --batch-mode --update-snapshots verify ${MAVEN_ARGS} +find ./gson -name "gson-*.jar" -exec mv {} $OUT/gson.jar \; + +ALL_JARS="gson.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 diff --git a/projects/gson/gson/pom.xml b/projects/gson/gson/pom.xml new file mode 100644 index 000000000..edbefc75c --- /dev/null +++ b/projects/gson/gson/pom.xml @@ -0,0 +1,110 @@ + + 4.0.0 + + + com.google.code.gson + gson-parent + 2.9.0-SNAPSHOT + + + gson + Gson + + + 7.1.1 + + + + + Apache-2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + com.google.gson + com.google.gson.internal:com.google.gson.internal.bind + + https://docs.oracle.com/javase/6/docs/api/ + + + + + biz.aQute.bnd + bnd-maven-plugin + 6.0.0 + + + + bnd-process + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filtering-java-templates + + filter-sources + + + ${basedir}/src/main/java-templates + ${project.build.directory}/generated-sources/java-templates + + + + + + maven-resources-plugin + 3.2.0 + + + post-obfuscate-class + process-test-classes + + copy-resources + + + ${project.build.directory}/test-classes/com/google/gson/functional + + + ${project.build.directory}/test-classes-obfuscated-outjar/com/google/gson/functional + + EnumWithObfuscatedTest.class + EnumWithObfuscatedTest$Gender.class + + + + + + + + + + diff --git a/projects/gson/pom.xml b/projects/gson/pom.xml new file mode 100644 index 000000000..e0e5b366f --- /dev/null +++ b/projects/gson/pom.xml @@ -0,0 +1,158 @@ + + + + 4.0.0 + + + org.sonatype.oss + oss-parent + 7 + + + com.google.code.gson + gson-parent + 2.9.0-SNAPSHOT + pom + + Gson Parent + Gson JSON library + https://github.com/google/gson + + + gson + extras + + + + UTF-8 + 1.6 + + + + https://github.com/google/gson/ + scm:git:https://github.com/google/gson.git + scm:git:git@github.com:google/gson.git + HEAD + + + + GitHub Issues + https://github.com/google/gson/issues + + + + + Apache-2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + + junit + junit + 4.13.2 + test + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + default-compile + + + 9 + + 9 + + + + base-compile + + compile + + + + module-info.java + + + + + + + [1.5,9) + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.1 + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + org.apache.felix + maven-bundle-plugin + 5.1.2 + true + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + + org.apache.maven.scm + maven-scm-api + 1.11.3 + + + org.apache.maven.scm + maven-scm-provider-gitexe + 1.12.0 + + + + true + + + + + + + doclint-java8-disable + + [1.8,) + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + -Xdoclint:none + + + + + + + diff --git a/projects/gson/project.yaml b/projects/gson/project.yaml new file mode 100644 index 000000000..a88b55806 --- /dev/null +++ b/projects/gson/project.yaml @@ -0,0 +1,10 @@ +homepage: "https://github.com/google/gson" +language: jvm +primary_contact: "emcmanus@google.com" +main_repo: "https://github.com/google/gson" +auto_ccs: + - "david@adalogics.com" +fuzzing_engines: + - libfuzzer +sanitizers: + - address