diff options
author | Dominik Stadler <centic@apache.org> | 2023-08-07 15:15:38 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2023-08-07 15:15:38 +0000 |
commit | 5efa428ca0cbf421fa394c53b600d9f242d69e0f (patch) | |
tree | 514d16f5ccc8cd3157e641599859a0b337228fbe /poi-integration | |
parent | 2c5264277a879b4adba6593b79053fbb8ae4df29 (diff) | |
download | poi-5efa428ca0cbf421fa394c53b600d9f242d69e0f.tar.gz poi-5efa428ca0cbf421fa394c53b600d9f242d69e0f.zip |
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
Diffstat (limited to 'poi-integration')
-rw-r--r-- | poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java index a48d0cbc29..ed96cde4e8 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java @@ -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)) { - if (actMsg != null) { - assertTrue(actMsg.contains(exMessage), errPrefix + "Message: "+actMsg+" - didn't contain: "+exMessage); - } - } else { - assertNotNull(actMsg, errPrefix); + + // 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); } |