aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2024-04-22 13:32:30 +0000
committerDominik Stadler <centic@apache.org>2024-04-22 13:32:30 +0000
commit3800aa541814ff77eeba60f4f2e0aeb6974f4f18 (patch)
tree780310e2a9e6668e5b1842152d108d49da2be2b4 /poi
parent91149769e4fd1855c8dff20472debcdbffd2b462 (diff)
downloadpoi-3800aa541814ff77eeba60f4f2e0aeb6974f4f18.tar.gz
poi-3800aa541814ff77eeba60f4f2e0aeb6974f4f18.zip
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
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/DocumentSummaryInformation.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java39
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java1
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java1
4 files changed, 35 insertions, 8 deletions
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;
}