Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ rat {
// ignore svn conflict artifacts
"**/module-info.*",
"poi-examples/src/main/groovy/settings.gradle",
"poi-examples/src/main/groovy/.gradle/**"
"poi-examples/src/main/groovy/.gradle/**",
"**/*.dict"
]

/*
Expand Down
3 changes: 3 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ under the License.
<dependency prefix="main.log4j-core" artifact="org.apache.logging.log4j:log4j-core:2.25.3" usage="main-tests"/>
<dependency prefix="main.commons-logging" artifact="commons-logging:commons-logging:1.2" usage="main-tests"/>

<dependency prefix="main.jazzer-api" artifact="com.code-intelligence:jazzer-api:0.22.0" usage="main-tests"/>

<dependency prefix="main.ant" artifact="org.apache.ant:ant:1.10.15" usage="excelant"/>
<dependency prefix="main.antlauncher" artifact="org.apache.ant:ant-launcher:1.10.15" usage="excelant"/>

Expand Down Expand Up @@ -442,6 +444,7 @@ under the License.
<pathelement location="${main.objenesis.jar}"/>
<pathelement location="${main.log4j-core.jar}"/>
<pathelement location="${main.commons-logging.jar}"/>
<pathelement location="${main.jazzer-api.jar}"/>
</path>

<path id="scratchpad.classpath">
Expand Down
1 change: 1 addition & 0 deletions poi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {

testImplementation 'org.reflections:reflections:0.10.2'
testImplementation 'org.apache.ant:ant:1.10.15'
testImplementation 'com.code-intelligence:jazzer-api:0.22.0'

testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
Expand Down
48 changes: 48 additions & 0 deletions poi/src/test/java/org/apache/poi/fuzz/FormulaParserFuzzer.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Excel Formula Dictionary for FormulaParserFuzzer
"SUM"
"AVERAGE"
"COUNT"
"IF"
"VLOOKUP"
"Table1"
"["
"]"
"[["
"]]"
"#"
"#All"
"#Headers"
"#Data"
"#Totals"
"#This Row"
"'"
"!"
":"
","
"("
")"
"\""
"+"
"-"
"*"
"/"
"^"
"&"
"="
"<"
">"
"<="
">="
"<>"
"$"
"."
" "
"@"
"A1"
"B2"
"C3"
"Sheet1"
"Sheet2"
"NamedRange"
"Column1"
"Column2"
63 changes: 63 additions & 0 deletions poi/src/test/java/org/apache/poi/fuzz/FormulaParserFuzzer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* ====================================================================
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.
==================================================================== */

package org.apache.poi.fuzz;

import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.FormulaParser;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.util.RecordFormatException;

import java.nio.BufferUnderflowException;
import java.util.NoSuchElementException;

/**
* Fuzz target for the Apache POI Formula Parser.
* Used by Google's OSS-Fuzz for continuous security testing.
*/
public class FormulaParserFuzzer {
private static HSSFWorkbook workbook;
private static HSSFEvaluationWorkbook evalWorkbook;

public static void fuzzerInitialize() {
workbook = new HSSFWorkbook();
evalWorkbook = HSSFEvaluationWorkbook.create(workbook);
}

public static void fuzzerTestOneInput(FuzzedDataProvider data) {
try {
FormulaType formulaType = data.pickValue(FormulaType.values());
int sheetIndex = data.consumeInt(-1, 10);
String formula = data.consumeRemainingAsString();

if (formula == null || formula.isEmpty()) {
return;
}

FormulaParser.parse(formula, evalWorkbook, formulaType, sheetIndex);

} catch (FormulaParseException | IllegalArgumentException | IllegalStateException |
IndexOutOfBoundsException | ArithmeticException | NegativeArraySizeException |
RecordFormatException | BufferUnderflowException |
UnsupportedOperationException | NoSuchElementException e) {
// Expected exceptions on malformed formula syntax
}
}
}
45 changes: 45 additions & 0 deletions poi/src/test/java/org/apache/poi/fuzz/POIRleFuzzer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* ====================================================================
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.
==================================================================== */

package org.apache.poi.fuzz;

import org.apache.poi.util.RLEDecompressingInputStream;

import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
* Fuzz target for RLEDecompressingInputStream.
* Used by Google's OSS-Fuzz for continuous security testing.
*/
public class POIRleFuzzer {
public static void fuzzerInitialize() {
}

public static void fuzzerTestOneInput(byte[] input) {
try (RLEDecompressingInputStream rleStream =
new RLEDecompressingInputStream(new ByteArrayInputStream(input))) {

byte[] buffer = new byte[1024];
while (rleStream.read(buffer) != -1) {
// Trigger decompression logic
}
} catch (IOException | IllegalArgumentException | IllegalStateException | IndexOutOfBoundsException e) {
// Expected exceptions on malformed input
}
}
}
1 change: 1 addition & 0 deletions poi/src/test/java9/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;
requires org.mockito;
requires static com.code_intelligence.jazzer.api;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not do this - move the code out of here into its own module if this is needed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you even host this change yourself? Why does this code need to be in POI repo. It can be in any arbitrary Git repo.


exports org.apache.poi.hpsf.basic to org.junit.platform.commons;
exports org.apache.poi.hssf.record.pivot to org.junit.platform.commons;
Expand Down