You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2026/10/26 20:09:29 UTC

(poi) 06/07: Fuzzing: Make it possible to compute coverage of fuzzing

This is an automated email from the ASF dual-hosted git repository.

centic9 pushed a commit to branch npes_fuzzing_and_test_improvements
in repository https://gitbox.apache.org/repos/asf/poi.git

commit fa4f27c66158285053853dab1982a961da287bbe
Author: Dominik Stadler <ce...@apache.org>
AuthorDate: Mon Oct 26 09:43:38 2026 +0100

    Fuzzing: Make it possible to compute coverage of fuzzing
    
    The script records coverage of all files currently
    in the corpus-directories.
    
    This allows to check which areas of the code are
    well-covered already and which one could use a
    dedicated fuzz-target.
---
 .gitignore                 |   1 +
 poi-fuzz/build.gradle      |  32 ++++++++++++
 poi-fuzz/coverageReport.sh | 124 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 157 insertions(+)

diff --git a/.gitignore b/.gitignore
index 5c89de9eac..0440e06c47 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,6 +37,7 @@ TEST-org.apache.poi*.xml
 /*/build/
 dist
 lib/
+/poi-fuzz/jacoco-*.zip
 /poi-fuzz/jazzer
 /poi-fuzz/jazzer-*.tar.gz
 /poi-fuzz/jazzer_standalone.jar
diff --git a/poi-fuzz/build.gradle b/poi-fuzz/build.gradle
index 8815205fd1..fdfb1ff9c8 100644
--- a/poi-fuzz/build.gradle
+++ b/poi-fuzz/build.gradle
@@ -70,7 +70,39 @@ tasks.register('testJar', Jar) {
     from sourceSets.test.output + sourceSets.main.output
 }
 
+
+tasks.register('getFuzzDeps', Copy) {
+    from sourceSets.main.runtimeClasspath
+    into 'build/runtime/'
+}
+
 shadowJar{
     // set name to not include the version in the file-name
     archiveFileName = "poi-fuzz-all.jar"
 }
+
+idea {
+    module {
+        excludeDirs += [
+            file("corpus"),
+            file("corpusCellFormat"),
+            file("corpusEncryptDecrypt"),
+            file("corpusFormulaParser"),
+            file("corpusHDGF"),
+            file("corpusHMEF"),
+            file("corpusHPBF"),
+            file("corpusHPSF"),
+            file("corpusHSLF"),
+            file("corpusHSMF"),
+            file("corpusHSSF"),
+            file("corpusHWPF"),
+            file("corpusOldExcel"),
+            file("corpusRle"),
+            file("corpusVisio"),
+            file("corpusXSLF"),
+            file("corpusXSSF"),
+            file("corpusXSSFB"),
+            file("corpusXWPF"),
+        ]
+    }
+}
diff --git a/poi-fuzz/coverageReport.sh b/poi-fuzz/coverageReport.sh
new file mode 100755
index 0000000000..6597154c87
--- /dev/null
+++ b/poi-fuzz/coverageReport.sh
@@ -0,0 +1,124 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+#
+# Small helper script to produce a coverage report when executing the fuzz-model
+# against the current corpus.
+#
+
+set -eu
+
+if [ $# -gt 0 ]; then
+  ONE=$1
+  echo
+  echo "Fuzzing only ${ONE}"
+else
+  ONE=
+fi
+
+
+# Build the fuzzer and fetch dependency-jars
+echo
+echo Rebuilding
+../gradlew shadowJar getFuzzDeps
+
+
+# extract jar-files of Apache POI
+mkdir -p build/poifiles
+cd build/poifiles
+
+# then unpack the class-files
+for i in `find ../runtime -name poi-*.jar`; do
+  echo $i
+  unzip -o -q $i
+done
+
+# Remove some packages that we do not want to include in the Report
+rm -r com
+rm -r org/openxmlformats
+rm -r org/etsi
+rm -r org/w3
+rm -r org/apache/poi/examples
+
+cd -
+
+
+
+# Fetch JaCoCo Agent
+test -f jacoco-0.8.15.zip || wget --continue https://repo1.maven.org/maven2/org/jacoco/jacoco/0.8.15/jacoco-0.8.15.zip
+unzip -o jacoco-0.8.15.zip lib/jacocoagent.jar lib/jacococli.jar
+mv lib/jacocoagent.jar lib/jacococli.jar build/
+rmdir lib
+
+mkdir -p build/jacoco
+
+echo
+if [[ "$(uname -s)" == CYGWIN* ]]; then
+  echo "Running under Cygwin"
+  JAZZER_DELIMITER=":"
+  PATH_DELIMITER=";"
+else
+  JAZZER_DELIMITER="\\:"
+  PATH_DELIMITER=":"
+fi
+
+
+for i in `cd src/main/java/org/apache/poi/fuzz/ && ls ${ONE}*Fuzzer.java`; do
+  CLASS=`echo $i | sed -e 's/.java//g'`
+  CORPUS=corpus`echo ${CLASS} | sed -e 's/Fuzzer//g' | sed -e 's/POI//g'`
+
+  # no separate corpus for this one
+  if [ "${CLASS}" == "XLSX2CSVFuzzer" ]; then
+    CORPUS=corpusXSSF
+  elif [ "${CLASS}" == "POIFileHandlerFuzzer" ]; then
+    CORPUS=corpus
+  fi
+
+  echo
+  echo Running jazzer for ${CLASS} and ${CORPUS}
+
+  # Run Jazzer with JaCoCo-Agent to produce coverage information
+  ./jazzer \
+    "--cp=build/poifiles${PATH_DELIMITER}build/libs/poi-fuzz-all.jar" \
+    "--instrumentation_includes=org.apache.poi.**${PATH_DELIMITER}org.apache.xmlbeans.**" \
+    --target_class=org.apache.poi.fuzz.${CLASS} \
+    --nohooks \
+    --jvm_args="-javaagent${JAZZER_DELIMITER}build/jacocoagent.jar=destfile=build/jacoco/${CORPUS}.exec" \
+    -rss_limit_mb=8192 \
+    -runs=0 \
+    ${CORPUS}
+done
+
+echo
+echo Having coverage-files
+ls -al build/jacoco/corpus*.exec
+
+# Finally create the JaCoCo report
+echo
+echo Creating JaCoCo report
+java -jar build/jacococli.jar report build/jacoco/corpus*.exec \
+ --classfiles build/poifiles \
+ --sourcefiles /opt/apache/poi/git-svn/poi/src/main/java \
+ --sourcefiles /opt/apache/poi/git-svn/poi-ooxml/src/main/java \
+ --sourcefiles /opt/apache/poi/git-svn/poi-ooxml-lite/src/main/java \
+ --sourcefiles /opt/apache/poi/git-svn/poi-scratchpad/src/main/java \
+ --sourcefiles /opt/apache/xmlbeans/trunk/src/main/java \
+ --sourcefiles src/main/java \
+ --html build/reports/jacoco
+
+
+echo All Done, report is at build/reports/jacoco/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org