From 15dd62d65957dc87b0aa2efab2f4561c17707607 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Wed, 6 Dec 2023 19:49:52 +0000 Subject: 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 --- .../org/apache/poi/stress/AbstractFileHandler.java | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'poi-integration') diff --git a/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java index c413fb0733..c1c96aaa12 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java @@ -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()); } } } -- cgit v1.2.3