From: Dominik Stadler Date: Mon, 22 Apr 2024 13:32:30 +0000 (+0000) Subject: Bug 66425: Avoid exceptions found via poi-fuzz X-Git-Tag: REL_5_3_0~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3800aa541814ff77eeba60f4f2e0aeb6974f4f18;p=poi.git Bug 66425: Avoid exceptions found via poi-fuzz Avoid a possible NullPointerException Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67922 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917269 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/main/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/poi/src/main/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index f96e12ac75..efd4c2d2f8 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/poi/src/main/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -767,7 +767,7 @@ public class DocumentSummaryInformation extends PropertySet { final long id = p.getID(); if (id == PropertyIDMap.PID_CODEPAGE) { cps.setCodepage((Integer)p.getValue()); - } else if (id > PropertyIDMap.PID_CODEPAGE) { + } else if (id > PropertyIDMap.PID_CODEPAGE && dictionary != null) { propertyCount++; final CustomProperty cp = new CustomProperty(p, dictionary.get(id)); cps.put(cp.getName(), cp); diff --git a/poi/src/test/java/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java b/poi/src/test/java/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java index 85d7d02b89..d6daec4732 100644 --- a/poi/src/test/java/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java +++ b/poi/src/test/java/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java @@ -17,14 +17,11 @@ package org.apache.poi.hpsf.extractor; -import static org.apache.poi.POITestCase.assertContains; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.io.IOException; -import java.io.InputStream; - +import org.apache.commons.io.FileUtils; import org.apache.poi.POIDataSamples; +import org.apache.poi.extractor.ExtractorFactory; +import org.apache.poi.extractor.POIOLE2TextExtractor; +import org.apache.poi.extractor.POITextExtractor; import org.apache.poi.hpsf.Thumbnail; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.extractor.ExcelExtractor; @@ -32,6 +29,15 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.junit.jupiter.api.Test; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.apache.poi.POITestCase.assertContains; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; + final class TestHPSFPropertiesExtractor { private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance(); @@ -179,4 +185,23 @@ final class TestHPSFPropertiesExtractor { assertContains(ext.getText(), "PID_CODEPAGE = 1252"); } } + + @Test + void testNPE() throws IOException { + final byte[] bytes = FileUtils.readFileToByteArray( + POIDataSamples.getSpreadSheetInstance().getFile( + "clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls")); + try (POITextExtractor extractor = ExtractorFactory.createExtractor(new ByteArrayInputStream(bytes))) { + assertInstanceOf(POIOLE2TextExtractor.class, extractor); + + POIOLE2TextExtractor ole2Extractor = (POIOLE2TextExtractor) extractor; + + POITextExtractor[] embedded = ExtractorFactory.getEmbeddedDocsTextExtractors(ole2Extractor); + assertEquals(1, embedded.length); + for (POITextExtractor poiTextExtractor : embedded) { + POITextExtractor metaData = poiTextExtractor.getMetadataTextExtractor(); + metaData.getText(); + } + } + } } diff --git a/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java b/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java index d23f1dbece..77f41647b7 100644 --- a/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java +++ b/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java @@ -47,6 +47,7 @@ class TestBiffViewer extends BaseTestIteratingXLS { excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", IndexOutOfBoundsException.class); excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", IndexOutOfBoundsException.class); excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", IndexOutOfBoundsException.class); + excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls", RecordFormatException.class); return excludes; } diff --git a/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java b/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java index 34359e1d2e..d244f3ff5a 100644 --- a/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java +++ b/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java @@ -50,6 +50,7 @@ class TestRecordLister extends BaseTestIteratingXLS { excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", RecordFormatException.class); excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", RecordFormatException.class); excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", RecordFormatException.class); + excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls", RecordFormatException.class); return excludes; } diff --git a/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls new file mode 100644 index 0000000000..3e327c6c85 Binary files /dev/null and b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls differ diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls index bedead8ec1..5a384cdef3 100644 Binary files a/test-data/spreadsheet/stress.xls and b/test-data/spreadsheet/stress.xls differ