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/src | |
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/src')
4 files changed, 11 insertions, 4 deletions
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java index ab7df1d733..1a0fca32e8 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java @@ -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: diff --git a/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java b/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java index 5ec8a30b23..45de3c2155 100644 --- a/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java +++ b/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java @@ -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); } } diff --git a/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java b/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java index 0b78830996..ea39f5147d 100644 --- a/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java +++ b/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java @@ -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; } diff --git a/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java b/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java index b904af8808..9a3bd3d649 100644 --- a/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java +++ b/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java @@ -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); } /** |