aboutsummaryrefslogtreecommitdiff
path: root/projects/apache-commons
diff options
context:
space:
mode:
authorMatt Juntunen <darkma773r@users.noreply.github.com>2021-07-31 22:02:37 -0400
committerGitHub <noreply@github.com>2021-08-01 02:02:37 +0000
commit290344bc6ab0097d12a1a62a9a920da82861110f (patch)
tree3d0f052c9ad2fef08b1ce80291e99e2929d31f38 /projects/apache-commons
parent3b4dfa5add28aff750729700d59a20eea8d6cb8f (diff)
downloadoss-fuzz-290344bc6ab0097d12a1a62a9a920da82861110f.tar.gz
adding commons-geometry to Apache Commons project files (#6144)
Diffstat (limited to 'projects/apache-commons')
-rw-r--r--projects/apache-commons/Dockerfile3
-rw-r--r--projects/apache-commons/GeometryObjFuzzer.java40
-rw-r--r--projects/apache-commons/GeometryStlBinaryFuzzer.java40
-rw-r--r--projects/apache-commons/GeometryStlTextFuzzer.java55
-rw-r--r--projects/apache-commons/GeometryTextFuzzer.java41
-rwxr-xr-xprojects/apache-commons/build.sh15
6 files changed, 191 insertions, 3 deletions
diff --git a/projects/apache-commons/Dockerfile b/projects/apache-commons/Dockerfile
index c94621015..c325ea756 100644
--- a/projects/apache-commons/Dockerfile
+++ b/projects/apache-commons/Dockerfile
@@ -52,6 +52,9 @@ RUN zip -uj $SRC/CompressTarFuzzer_seed_corpus.zip commons-compress/src/test/res
# Imaging
RUN git clone --depth 1 https://gitbox.apache.org/repos/asf/commons-imaging.git
+# Geometry
+RUN git clone --depth 1 https://gitbox.apache.org/repos/asf/commons-geometry.git
+
# Copy build script and all fuzzers
COPY build.sh $SRC/
COPY *Fuzzer.java $SRC/
diff --git a/projects/apache-commons/GeometryObjFuzzer.java b/projects/apache-commons/GeometryObjFuzzer.java
new file mode 100644
index 000000000..6b8900f4b
--- /dev/null
+++ b/projects/apache-commons/GeometryObjFuzzer.java
@@ -0,0 +1,40 @@
+// 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.ByteArrayInputStream;
+import java.io.UncheckedIOException;
+
+import org.apache.commons.geometry.io.core.input.StreamGeometryInput;
+import org.apache.commons.geometry.io.euclidean.threed.BoundaryReadHandler3D;
+import org.apache.commons.geometry.io.euclidean.threed.obj.ObjBoundaryReadHandler3D;
+import org.apache.commons.numbers.core.Precision;
+
+public class GeometryObjFuzzer {
+ public static void fuzzerTestOneInput(final byte[] data) {
+ try {
+ final BoundaryReadHandler3D handler = new ObjBoundaryReadHandler3D();
+ final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-20);
+
+ // check standard read
+ handler.read(new StreamGeometryInput(new ByteArrayInputStream(data)), precision);
+
+ // check mesh read
+ handler.readTriangleMesh(new StreamGeometryInput(new ByteArrayInputStream(data)), precision);
+ } catch (UncheckedIOException | IllegalArgumentException | IllegalStateException ignored) {
+ // expected exception types; ignore
+ }
+ }
+}
diff --git a/projects/apache-commons/GeometryStlBinaryFuzzer.java b/projects/apache-commons/GeometryStlBinaryFuzzer.java
new file mode 100644
index 000000000..3df154700
--- /dev/null
+++ b/projects/apache-commons/GeometryStlBinaryFuzzer.java
@@ -0,0 +1,40 @@
+// 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.ByteArrayInputStream;
+import java.io.UncheckedIOException;
+
+import org.apache.commons.geometry.io.core.input.StreamGeometryInput;
+import org.apache.commons.geometry.io.euclidean.threed.BoundaryReadHandler3D;
+import org.apache.commons.geometry.io.euclidean.threed.stl.StlBoundaryReadHandler3D;
+import org.apache.commons.numbers.core.Precision;
+
+public class GeometryStlBinaryFuzzer {
+ public static void fuzzerTestOneInput(final byte[] data) {
+ try {
+ final BoundaryReadHandler3D handler = new StlBoundaryReadHandler3D();
+ final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-20);
+
+ // check standard read
+ handler.read(new StreamGeometryInput(new ByteArrayInputStream(data)), precision);
+
+ // check mesh read
+ handler.readTriangleMesh(new StreamGeometryInput(new ByteArrayInputStream(data)), precision);
+ } catch (UncheckedIOException | IllegalArgumentException | IllegalStateException ignored) {
+ // expected exception types; ignore
+ }
+ }
+}
diff --git a/projects/apache-commons/GeometryStlTextFuzzer.java b/projects/apache-commons/GeometryStlTextFuzzer.java
new file mode 100644
index 000000000..5bddb17d5
--- /dev/null
+++ b/projects/apache-commons/GeometryStlTextFuzzer.java
@@ -0,0 +1,55 @@
+// 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.nio.charset.StandardCharsets;
+
+import java.io.ByteArrayInputStream;
+import java.io.UncheckedIOException;
+
+import org.apache.commons.geometry.io.core.input.StreamGeometryInput;
+import org.apache.commons.geometry.io.euclidean.threed.BoundaryReadHandler3D;
+import org.apache.commons.geometry.io.euclidean.threed.stl.StlBoundaryReadHandler3D;
+import org.apache.commons.numbers.core.Precision;
+
+public class GeometryStlTextFuzzer {
+ public static void fuzzerTestOneInput(final byte[] data) {
+ // prepend the "solid" STL keyword to the input to ensure it is interpreted
+ // as text STL input
+ final byte[] dataWithPrefix = join("solid ".getBytes(StandardCharsets.US_ASCII), data);
+
+ try {
+ final BoundaryReadHandler3D handler = new StlBoundaryReadHandler3D();
+
+ final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-20);
+
+ // check standard read
+ handler.read(new StreamGeometryInput(new ByteArrayInputStream(dataWithPrefix)), precision);
+
+ // check mesh read
+ handler.readTriangleMesh(new StreamGeometryInput(new ByteArrayInputStream(dataWithPrefix)), precision);
+ } catch (UncheckedIOException | IllegalArgumentException | IllegalStateException ignored) {
+ // expected exception types; ignore
+ }
+ }
+
+ private static byte[] join(final byte[] a, final byte[] b) {
+ final byte[] result = new byte[a.length + b.length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+
+ return result;
+ }
+}
diff --git a/projects/apache-commons/GeometryTextFuzzer.java b/projects/apache-commons/GeometryTextFuzzer.java
new file mode 100644
index 000000000..ab318f2a8
--- /dev/null
+++ b/projects/apache-commons/GeometryTextFuzzer.java
@@ -0,0 +1,41 @@
+// 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.ByteArrayInputStream;
+import java.io.UncheckedIOException;
+
+import org.apache.commons.geometry.io.core.input.StreamGeometryInput;
+import org.apache.commons.geometry.io.euclidean.threed.BoundaryReadHandler3D;
+import org.apache.commons.geometry.io.euclidean.threed.txt.TextBoundaryReadHandler3D;
+import org.apache.commons.numbers.core.Precision;
+
+public class GeometryTextFuzzer {
+ public static void fuzzerTestOneInput(final byte[] data) {
+ try {
+ final BoundaryReadHandler3D handler = new TextBoundaryReadHandler3D();
+
+ final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-20);
+
+ // check standard read
+ handler.read(new StreamGeometryInput(new ByteArrayInputStream(data)), precision);
+
+ // check mesh read
+ handler.readTriangleMesh(new StreamGeometryInput(new ByteArrayInputStream(data)), precision);
+ } catch (UncheckedIOException | IllegalArgumentException | IllegalStateException ignored) {
+ // expected exception types; ignore
+ }
+ }
+}
diff --git a/projects/apache-commons/build.sh b/projects/apache-commons/build.sh
index 46fa6e11e..6716afdfa 100755
--- a/projects/apache-commons/build.sh
+++ b/projects/apache-commons/build.sh
@@ -18,15 +18,24 @@
# Move seed corpus and dictionary.
mv $SRC/{*.zip,*.dict} $OUT
-PROJECTS="compress imaging"
+PROJECTS="compress imaging geometry"
+GEOMETRY_MODULE="commons-geometry-io-euclidean"
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
+
+ if [ $project = 'geometry' ]; then
+ # commons-geometry is a multi-module project and requires special handling in order
+ # to build and extract the proper module (commons-geometry-io-euclidean)
+ $MVN package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade -am -pl $GEOMETRY_MODULE $MAVEN_ARGS
+ cp "$GEOMETRY_MODULE/target/$GEOMETRY_MODULE-$CURRENT_VERSION.jar" $OUT/commons-$project.jar
+ else
+ $MVN package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade $MAVEN_ARGS
+ cp "target/commons-$project-$CURRENT_VERSION.jar" $OUT/commons-$project.jar
+ fi
ALL_JARS="commons-$project.jar"