Browse Source

Bug 66425: Avoid exceptions found via poi-fuzz

Avoid a ClassCastException and trigger some more
code in integration-testing.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63358

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1914404 13f79535-47bb-0310-9956-ffa450edef68
pull/562/head
Dominik Stadler 5 months ago
parent
commit
15dd62d659

+ 28
- 1
poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java View File

@@ -109,13 +109,38 @@ public abstract class AbstractFileHandler implements FileHandler {
assertEquals(modified, file.lastModified(), "File should not be modified by extractor");

if (extractor instanceof POIOLE2TextExtractor) {
try (HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor)) {
POIOLE2TextExtractor ole2Extractor = (POIOLE2TextExtractor) extractor;
ole2Extractor.getRoot();
if (!(ole2Extractor instanceof EventBasedExcelExtractor)) {
ole2Extractor.getSummaryInformation();
ole2Extractor.getDocSummaryInformation();
}

try (HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor(ole2Extractor)) {
assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
assertNotNull(hpsfExtractor.getSummaryInformationText());
String text = hpsfExtractor.getText();
//System.out.println(text);
assertNotNull(text);
}

if (ole2Extractor.getRoot() != null && !Boolean.getBoolean("scratchpad.ignore")) {
POITextExtractor[] embedded = ExtractorFactory.getEmbeddedDocsTextExtractors(ole2Extractor);
try {
for (POITextExtractor poiTextExtractor : embedded) {
poiTextExtractor.getText();
poiTextExtractor.getDocument();
poiTextExtractor.getFilesystem();
POITextExtractor metaData = poiTextExtractor.getMetadataTextExtractor();
metaData.getFilesystem();
metaData.getText();
}
} finally {
for (POITextExtractor embeddedExtractor : embedded) {
embeddedExtractor.close();
}
}
}
}

// test again with including formulas and cell-comments as this caused some bugs
@@ -166,6 +191,8 @@ public abstract class AbstractFileHandler implements FileHandler {
assertNotNull(streamExtractor);

assertNotNull(streamExtractor.getText());

assertNotNull(streamExtractor.getMetadataTextExtractor());
}
}
}

+ 3
- 1
poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java View File

@@ -373,7 +373,9 @@ public final class ExtractorFactory {

ArrayList<POITextExtractor> textExtractors = new ArrayList<>();
for (Entry dir : dirs) {
textExtractors.add(createExtractor((DirectoryNode) dir));
if (dir instanceof DirectoryNode) {
textExtractors.add(createExtractor((DirectoryNode) dir));
}
}
for (InputStream stream : nonPOIFS) {
try {

+ 1
- 0
poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java View File

@@ -44,6 +44,7 @@ class TestBiffViewer extends BaseTestIteratingXLS {
excludes.put("protected_66115.xls", RecordFormatException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5786329142919168.xls", IllegalStateException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5889658057523200.xls", IndexOutOfBoundsException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", IndexOutOfBoundsException.class);

return excludes;
}

+ 1
- 0
poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java View File

@@ -47,6 +47,7 @@ class TestRecordLister extends BaseTestIteratingXLS {
Map<String, Class<? extends Throwable>> excludes = super.getExcludes();
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5786329142919168.xls", RecordFormatException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5889658057523200.xls", IndexOutOfBoundsException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", RecordFormatException.class);
return excludes;
}


BIN
test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls View File


BIN
test-data/spreadsheet/stress.xls View File


Loading…
Cancel
Save