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

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

commit f81255d3e14cf7d7255afc6e377958263437f871
Author: Dominik Stadler <[email protected]>
AuthorDate: Fri Aug 7 08:17:37 2026 +0200

    Avoid an NPE when parsing formulas with strange sheet identifiers
    
    Add some simple tests for fuzz-targets
    
    Can be also used for manual testing of reproducers
---
 poi-fuzz/build.gradle                              | 17 ++++++++++++----
 .../apache/poi/fuzz/TestFormulaParserFuzzer.java   | 23 ++++++++++++++++++++++
 .../org/apache/poi/ss/formula/FormulaParser.java   |  2 +-
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/poi-fuzz/build.gradle b/poi-fuzz/build.gradle
index 2488b23da2..5cfa1f8013 100644
--- a/poi-fuzz/build.gradle
+++ b/poi-fuzz/build.gradle
@@ -28,15 +28,24 @@ dependencies {
     implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
     implementation 'org.apache.commons:commons-lang3:3.20.0'
     implementation 'org.opentest4j:opentest4j:1.3.0'
+    implementation 'com.code-intelligence:jazzer-api:0.30.0'
 
-    compileOnly 'com.code-intelligence:jazzer-api:0.30.0'
+    testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
+    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
+    testRuntimeOnly "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
 }
 
-// Fuzz targets are not standard JUnit tests; disable the test task.
-test.enabled = false
-
 javadoc.enabled = false
 sourcesJar.enabled = false
 
 generateMetadataFileForPOIPublication.enabled = false
 publishPOIPublicationToMavenLocal.enabled = false
+
+// Create a separate jar for test-code to depend on it in other projects
+// See http://stackoverflow.com/questions/5144325/gradle-test-dependency
+tasks.register('testJar', Jar) {
+    dependsOn testClasses
+    destinationDirectory = 
file("../build/dist/maven/${base.archivesName.get()}-tests")
+    setArchiveClassifier 'tests'
+    from sourceSets.test.output + sourceSets.main.output
+}
diff --git 
a/poi-fuzz/src/test/java/org/apache/poi/fuzz/TestFormulaParserFuzzer.java 
b/poi-fuzz/src/test/java/org/apache/poi/fuzz/TestFormulaParserFuzzer.java
new file mode 100644
index 0000000000..876ddf7a79
--- /dev/null
+++ b/poi-fuzz/src/test/java/org/apache/poi/fuzz/TestFormulaParserFuzzer.java
@@ -0,0 +1,23 @@
+package org.apache.poi.fuzz;
+
+import org.junit.jupiter.api.Test;
+
+import com.code_intelligence.jazzer.api.CannedFuzzedDataProvider;
+
+class TestFormulaParserFuzzer {
+    @Test
+    void test() {
+        String base64Bytes =
+                
"rO0ABXNyABNqYXZhLnV0aWwuQXJyYXlMaXN0eIHSHZnHYZ0DAAFJAARzaXpleHAAAAADdwQAAAADc3IAEWphdmEubGFuZy5JbnRlZ2VyEuKgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAJzcQB+AAIAAAAIdAAIWwxdIUXpiKl4";
+        CannedFuzzedDataProvider input = new 
CannedFuzzedDataProvider(base64Bytes);
+        FormulaParserFuzzer.fuzzerTestOneInput(input);
+    }
+
+    @Test
+    void testNPE() {
+        String base64Bytes =
+                
"rO0ABXNyABNqYXZhLnV0aWwuQXJyYXlMaXN0eIHSHZnHYZ0DAAFJAARzaXpleHAAAAADdwQAAAADc3IAEWphdmEubGFuZy5JbnRlZ2VyEuKgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAABzcQB+AAIAAAAHdAAJWwpdIUlROgoKeA==";
+        CannedFuzzedDataProvider input = new 
CannedFuzzedDataProvider(base64Bytes);
+        FormulaParserFuzzer.fuzzerTestOneInput(input);
+    }
+}
\ No newline at end of file
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java 
b/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java
index ecb3586de6..c72aadf1d7 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java
@@ -524,7 +524,7 @@ public final class FormulaParser {
                 resetPointer(colonPos);
                 if (!part1.isCell()) {
                     String prefix = "";
-                    if (sheetIden != null) {
+                    if (sheetIden != null && sheetIden.getSheetIdentifier() != 
null) {
                         prefix = "'" + 
sheetIden.getSheetIdentifier().getName() + '!';
                     }
                     throw new FormulaParseException(prefix + part1.getRep() + 
"' is not a proper reference.");


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to