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
This commit is contained in:
Dominik Stadler 2024-04-22 13:32:30 +00:00
parent 91149769e4
commit 3800aa5418
6 changed files with 35 additions and 8 deletions

View 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);

View File

@ -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();
}
}
}
}

View 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;
}

View 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;
}

Binary file not shown.