diff options
author | Dominik Stadler <centic@apache.org> | 2023-08-05 12:13:13 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2023-08-05 12:13:13 +0000 |
commit | 57d746827f48710f094b09f5d4a24090be97d4fb (patch) | |
tree | fc3891203983c28f7b1d375370cfc10c35432f91 /poi-scratchpad | |
parent | acf61f325f24307e6af7767f34e027aef81d4932 (diff) | |
download | poi-57d746827f48710f094b09f5d4a24090be97d4fb.tar.gz poi-57d746827f48710f094b09f5d4a24090be97d4fb.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=61162
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911459 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad')
-rw-r--r-- | poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java index a723fc2cc1..c3d44099de 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java @@ -23,6 +23,7 @@ import java.io.InputStream; import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.poi.poifs.filesystem.DirectoryNode; +import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.util.IOUtils; /** @@ -57,7 +58,11 @@ public abstract class HPBFPart { DirectoryNode dir = baseDir; for(int i=0; i<path.length-1; i++) { 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) { throw new IllegalArgumentException("File invalid - failed to find directory entry '" + path[i] + "': " + e); |