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=61242

Also enhance output of some test-failures and allow an empty exception message

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911515 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2023-08-07 15:15:38 +00:00
parent 2c5264277a
commit 5efa428ca0
7 changed files with 18 additions and 10 deletions

View File

@ -42,6 +42,7 @@ import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.platform.commons.util.StringUtils;
import org.opentest4j.AssertionFailedError;
/**
@ -251,12 +252,12 @@ public class TestAllFiles {
} else if (exClass != null) {
Exception e = assertThrows((Class<? extends Exception>)exClass, exec, errPrefix + " expected " + exClass);
String actMsg = pathReplace(e.getMessage());
if (NullPointerException.class.isAssignableFrom(exClass)) {
// verify that message is either null for both or set for both
assertTrue(actMsg != null || StringUtils.isBlank(exMessage),
errPrefix + " for " + exClass + " expected message '" + exMessage + "' but had '" + actMsg + "'");
if (actMsg != null) {
assertTrue(actMsg.contains(exMessage), errPrefix + "Message: "+actMsg+" - didn't contain: "+exMessage);
}
} else {
assertNotNull(actMsg, errPrefix);
assertTrue(actMsg.contains(exMessage),
errPrefix + "Message: " + actMsg + " - didn't contain: " + exMessage);
}

View File

@ -54,7 +54,11 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
// read internal and external coordinates from spgrContainer
EscherContainerRecord spContainer = spgrContainer.getChildContainers().get(0);
_spgrRecord = (EscherSpgrRecord) spContainer.getChild(0);
final EscherRecord child = spContainer.getChild(0);
if (!(child instanceof EscherSpgrRecord)) {
throw new IllegalArgumentException("Had unexpected type of child at index 0: " + child.getClass());
}
_spgrRecord = (EscherSpgrRecord) child;
for (EscherRecord ch : spContainer) {
switch (EscherRecordTypes.forTypeID(ch.getRecordId())) {
case CLIENT_ANCHOR:

View File

@ -102,9 +102,9 @@ public abstract class BaseTestIteratingXLS {
Executable ex = () -> runOneFile(file);
if (t == null) {
assertDoesNotThrow(ex);
assertDoesNotThrow(ex, "Failing file: " + file);
} else {
assertThrows(t, ex);
assertThrows(t, ex, "Failing file: " + file);
}
}

View File

@ -54,6 +54,7 @@ class TestBiffDrawingToXml extends BaseTestIteratingXLS {
excludes.put("43493.xls", RecordInputStream.LeftoverDataException.class);
excludes.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
excludes.put("protected_66115.xls", EncryptedDocumentException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5285517825277952.xls", IllegalArgumentException.class);
return excludes;
}

View File

@ -136,7 +136,9 @@ class TestDrawingAggregate {
File[] files = testData.listFiles((dir, name) -> name.endsWith(".xls"));
assertNotNull(files, "Need to find files in test-data path, had path: " + testData);
return Stream.of(files).map(Arguments::of);
return Stream.of(files).
filter(file -> !file.getName().equals("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5285517825277952.xls")).
map(Arguments::of);
}
/**

Binary file not shown.