]> source.dussan.org Git - poi.git/commitdiff
Bug 66425: Avoid exceptions found via poi-fuzz
authorDominik Stadler <centic@apache.org>
Mon, 22 Apr 2024 13:32:30 +0000 (13:32 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 22 Apr 2024 13:32:30 +0000 (13:32 +0000)
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

poi/src/main/java/org/apache/poi/hpsf/DocumentSummaryInformation.java
poi/src/test/java/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java
poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java
test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls [new file with mode: 0644]
test-data/spreadsheet/stress.xls

index f96e12ac75ec317180fb5971b903407a058f1eb0..efd4c2d2f854c2365a6ce68fbcaaa409eae075a9 100644 (file)
@@ -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);
index 85d7d02b89db79fc9fee0866209df7d006a58614..d6daec4732ce69141eca6f308cdeabe2342a1093 100644 (file)
 
 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();
+            }
+        }
+    }
 }
index d23f1dbecef5d24f54cfd6e22ba2256b41efc33d..77f41647b78aef27917c0398936899cc47ee8dca 100644 (file)
@@ -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;
     }
index 34359e1d2e81db24c7ca0c9886a2296f631ccd52..d244f3ff5ade9cc5ab344c71303685f76b700233 100644 (file)
@@ -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 (file)
index 0000000..3e327c6
Binary files /dev/null and b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls differ
index bedead8ec1147884b1748f6c528038b850e3102f..5a384cdef31c0a4c9fb0322cc3d4690adf615063 100644 (file)
Binary files a/test-data/spreadsheet/stress.xls and b/test-data/spreadsheet/stress.xls differ