mirror of https://github.com/apache/poi.git
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:
parent
2c5264277a
commit
5efa428ca0
|
@ -42,6 +42,7 @@ import org.junit.jupiter.api.parallel.ExecutionMode;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.junit.platform.commons.util.StringUtils;
|
||||||
import org.opentest4j.AssertionFailedError;
|
import org.opentest4j.AssertionFailedError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -251,12 +252,12 @@ public class TestAllFiles {
|
||||||
} else if (exClass != null) {
|
} else if (exClass != null) {
|
||||||
Exception e = assertThrows((Class<? extends Exception>)exClass, exec, errPrefix + " expected " + exClass);
|
Exception e = assertThrows((Class<? extends Exception>)exClass, exec, errPrefix + " expected " + exClass);
|
||||||
String actMsg = pathReplace(e.getMessage());
|
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) {
|
if (actMsg != null) {
|
||||||
assertTrue(actMsg.contains(exMessage), errPrefix + "Message: "+actMsg+" - didn't contain: "+exMessage);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
assertNotNull(actMsg, errPrefix);
|
|
||||||
assertTrue(actMsg.contains(exMessage),
|
assertTrue(actMsg.contains(exMessage),
|
||||||
errPrefix + "Message: " + actMsg + " - didn't contain: " + exMessage);
|
errPrefix + "Message: " + actMsg + " - didn't contain: " + exMessage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,11 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
|
||||||
|
|
||||||
// read internal and external coordinates from spgrContainer
|
// read internal and external coordinates from spgrContainer
|
||||||
EscherContainerRecord spContainer = spgrContainer.getChildContainers().get(0);
|
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) {
|
for (EscherRecord ch : spContainer) {
|
||||||
switch (EscherRecordTypes.forTypeID(ch.getRecordId())) {
|
switch (EscherRecordTypes.forTypeID(ch.getRecordId())) {
|
||||||
case CLIENT_ANCHOR:
|
case CLIENT_ANCHOR:
|
||||||
|
|
|
@ -102,9 +102,9 @@ public abstract class BaseTestIteratingXLS {
|
||||||
|
|
||||||
Executable ex = () -> runOneFile(file);
|
Executable ex = () -> runOneFile(file);
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
assertDoesNotThrow(ex);
|
assertDoesNotThrow(ex, "Failing file: " + file);
|
||||||
} else {
|
} else {
|
||||||
assertThrows(t, ex);
|
assertThrows(t, ex, "Failing file: " + file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ class TestBiffDrawingToXml extends BaseTestIteratingXLS {
|
||||||
excludes.put("43493.xls", RecordInputStream.LeftoverDataException.class);
|
excludes.put("43493.xls", RecordInputStream.LeftoverDataException.class);
|
||||||
excludes.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
excludes.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
||||||
excludes.put("protected_66115.xls", EncryptedDocumentException.class);
|
excludes.put("protected_66115.xls", EncryptedDocumentException.class);
|
||||||
|
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5285517825277952.xls", IllegalArgumentException.class);
|
||||||
return excludes;
|
return excludes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,9 @@ class TestDrawingAggregate {
|
||||||
|
|
||||||
File[] files = testData.listFiles((dir, name) -> name.endsWith(".xls"));
|
File[] files = testData.listFiles((dir, name) -> name.endsWith(".xls"));
|
||||||
assertNotNull(files, "Need to find files in test-data path, had path: " + testData);
|
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.
Binary file not shown.
Loading…
Reference in New Issue