Browse Source

Bug 66425: Avoid a ClassCastException found via oss-fuzz

We try to avoid throwing ClassCastException but it was possible
to trigger one here with a specially crafted input-file

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61162

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911459 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_4
Dominik Stadler 9 months ago
parent
commit
57d746827f

+ 2
- 8
poi-integration/src/test/java/org/apache/poi/stress/HPBFFileHandler.java View File

void test() throws Exception { void test() throws Exception {
File file = new File("test-data/publisher/SampleBrochure.pub"); File file = new File("test-data/publisher/SampleBrochure.pub");


InputStream stream = new FileInputStream(file);
try {
try (InputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath()); handleFile(stream, file.getPath());
} finally {
stream.close();
} }


handleExtracting(file); handleExtracting(file);


stream = new FileInputStream(file);
try {
try (InputStream stream = new FileInputStream(file)) {
try (PublisherTextExtractor extractor = new PublisherTextExtractor(stream)) { try (PublisherTextExtractor extractor = new PublisherTextExtractor(stream)) {
assertNotNull(extractor.getText()); assertNotNull(extractor.getText());
} }
} finally {
stream.close();
} }
} }



+ 6
- 1
poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java View File



import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;


/** /**
DirectoryNode dir = baseDir; DirectoryNode dir = baseDir;
for(int i=0; i<path.length-1; i++) { for(int i=0; i<path.length-1; i++) {
try { try {
dir = (DirectoryNode)dir.getEntry(path[i]);
Entry entry = dir.getEntry(path[i]);
if (!(entry instanceof DirectoryNode)) {
throw new IllegalArgumentException("Had unexpected type of entry for path: " + path[i] + ": " + entry);
}
dir = (DirectoryNode) entry;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new IllegalArgumentException("File invalid - failed to find directory entry '" throw new IllegalArgumentException("File invalid - failed to find directory entry '"
+ path[i] + "': " + e); + path[i] + "': " + e);

BIN
test-data/publisher/clusterfuzz-testcase-minimized-POIHPBFFuzzer-4701121678278656.pub View File


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


Loading…
Cancel
Save