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 f7737f04f80221330dc17464b8f17e8a3588cb55 Author: Dominik Stadler <[email protected]> AuthorDate: Mon Oct 26 09:07:12 2026 +0100 Add fuzzing for CellFormat and enable dictionaries --- .github/workflows/fuzzing.yml | 6 +- poi-fuzz/README.md | 7 ++- .../java/org/apache/poi/fuzz/CellFormatFuzzer.dict | 31 ++++++++++ .../java/org/apache/poi/fuzz/CellFormatFuzzer.java | 72 ++++++++++++++++++++++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fuzzing.yml b/.github/workflows/fuzzing.yml index f3b5f6f100..da7b6bb81e 100644 --- a/.github/workflows/fuzzing.yml +++ b/.github/workflows/fuzzing.yml @@ -65,6 +65,7 @@ jobs: mkdir -p corpusHMEF && cp -a corpus/hmef/* corpusHMEF/ mkdir -p corpusHPBF && cp -a corpus/publisher/* corpusHPBF/ mkdir -p corpusHSMF && cp -a corpus/hsmf/* corpusHSMF/ + mkdir -p corpusCellFormat mkdir -p corpusEncryptDecrypt mkdir -p corpusFormulaParser @@ -125,7 +126,10 @@ jobs: run: ./jazzer --cp=build/libs/poi-fuzz-all.jar "--instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.**" --target_class=org.apache.poi.fuzz.EncryptDecryptFuzzer -rss_limit_mb=4096 -timeout=120 -max_total_time=120 corpusEncryptDecrypt - name: Run Fuzzing - FormulaParserFuzzer - run: ./jazzer --cp=build/libs/poi-fuzz-all.jar "--instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.**" --target_class=org.apache.poi.fuzz.FormulaParserFuzzer -rss_limit_mb=4096 -timeout=120 -max_total_time=120 corpusFormulaParser + run: ./jazzer --cp=build/libs/poi-fuzz-all.jar "--instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.**" --target_class=org.apache.poi.fuzz.FormulaParserFuzzer -rss_limit_mb=4096 -timeout=120 -max_total_time=120 -dict=src/main/java/org/apache/poi/fuzz/FormulaParserFuzzer.dict corpusFormulaParser + + - name: Run Fuzzing - CellFormatFuzzer + run: ./jazzer --cp=build/libs/poi-fuzz-all.jar "--instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.**" --target_class=org.apache.poi.fuzz.CellFormatFuzzer -rss_limit_mb=4096 -timeout=120 -max_total_time=120 -dict=src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.dict corpusCellFormat - name: Run Fuzzing - POIFuzzer run: ./jazzer --cp=build/libs/poi-fuzz-all.jar --instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.** --target_class=org.apache.poi.fuzz.POIFuzzer -rss_limit_mb=4096 -timeout=600 -max_total_time=600 corpus diff --git a/poi-fuzz/README.md b/poi-fuzz/README.md index e9d2cbf0e9..d2ef853c06 100644 --- a/poi-fuzz/README.md +++ b/poi-fuzz/README.md @@ -165,7 +165,12 @@ Can re-use XSSF-corpus as the same files are processed here ## FormulaParser mkdir corpusFormulaParser - ../gradlew shadowJar && ./jazzer --cp=build/libs/poi-fuzz-all.jar "--instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.**" --target_class=org.apache.poi.fuzz.FormulaParserFuzzer -rss_limit_mb=2560 corpusFormulaParser + ../gradlew shadowJar && ./jazzer --cp=build/libs/poi-fuzz-all.jar "--instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.**" --target_class=org.apache.poi.fuzz.FormulaParserFuzzer -rss_limit_mb=2560 -dict=src/main/java/org/apache/poi/fuzz/FormulaParserFuzzer.dict corpusFormulaParser + +## CellFormatFuzzer + + mkdir corpusCellFormat + ../gradlew shadowJar && ./jazzer --cp=build/libs/poi-fuzz-all.jar "--instrumentation_includes=org.apache.poi.**:org.apache.xmlbeans.**" --target_class=org.apache.poi.fuzz.CellFormatFuzzer -rss_limit_mb=2560 -dict=src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.dict corpusCellFormat ## FileHandler diff --git a/poi-fuzz/src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.dict b/poi-fuzz/src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.dict new file mode 100644 index 0000000000..331abec325 --- /dev/null +++ b/poi-fuzz/src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.dict @@ -0,0 +1,31 @@ +# 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. + +# Excel Formula Dictionary for FormulaParserFuzzer +"$" +"#" +"_" +"(" +")" +";" +"[" +"Red" +"Green" +"]" +"\\" +"," +"." +"0" +"-" diff --git a/poi-fuzz/src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.java b/poi-fuzz/src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.java new file mode 100644 index 0000000000..a818db30c4 --- /dev/null +++ b/poi-fuzz/src/main/java/org/apache/poi/fuzz/CellFormatFuzzer.java @@ -0,0 +1,72 @@ +/* ==================================================================== + 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 static org.junit.jupiter.api.Assertions.assertThrows; + +import java.nio.BufferUnderflowException; +import java.nio.charset.StandardCharsets; +import java.util.Locale; +import java.util.NoSuchElementException; + +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.RandomUtils; +import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.format.CellFormat; +import org.apache.poi.ss.formula.FormulaParseException; +import org.apache.poi.ss.formula.FormulaParser; +import org.apache.poi.ss.formula.FormulaType; +import org.apache.poi.util.RecordFormatException; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; + +/** + * Fuzz target for the Apache POI cell formatter. + * Used by Google's OSS-Fuzz for continuous security testing. + */ +public class CellFormatFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + Locale locale = switch (data.consumeInt(0, 6)) { + case 0 -> Locale.ROOT; + case 1 -> Locale.ENGLISH; + case 2 -> Locale.GERMAN; + case 3 -> Locale.CANADA; + case 4 -> Locale.CHINESE; + case 5 -> Locale.JAPAN; + case 6 -> Locale.KOREAN; + default -> throw new IllegalArgumentException(); + }; + + Object obj = switch (data.consumeInt(0, 2)) { + case 0 -> data.consumeDouble(); + case 1 -> data.consumeLong(); + case 2 -> data.consumeString(data.consumeInt(0, 100)); + default -> throw new IllegalArgumentException(); + }; + + try { + CellFormat cellFormat = CellFormat.getInstance(locale, data.consumeRemainingAsString()); + + cellFormat.apply(obj); + } catch (IllegalArgumentException | IndexOutOfBoundsException | IllegalStateException | + ArithmeticException e) { + // expected + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
