From 9ae14ef6f024b9e5390614b0b2d455777eda3435 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 12 Aug 2023 17:37:14 +0000 Subject: 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=61400 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911618 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hsmf/datatypes/RecipientChunks.java | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'poi-scratchpad') diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/RecipientChunks.java b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/RecipientChunks.java index 8b37806fdc..d333a7b55d 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/RecipientChunks.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/RecipientChunks.java @@ -187,7 +187,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties { } /** Holds all the chunks that were found. */ - private List allChunks = new ArrayList<>(); + private final List allChunks = new ArrayList<>(); @Override public Map> getProperties() { @@ -212,21 +212,26 @@ public final class RecipientChunks implements ChunkGroupWithProperties { */ @Override public void record(Chunk chunk) { - if (chunk.getChunkId() == RECIPIENT_SEARCH.id) { - // TODO - parse - recipientSearchChunk = (ByteChunk) chunk; - } else if (chunk.getChunkId() == RECIPIENT_NAME.id) { - recipientDisplayNameChunk = (StringChunk) chunk; - } else if (chunk.getChunkId() == RECIPIENT_DISPLAY_NAME.id) { - recipientNameChunk = (StringChunk) chunk; - } else if (chunk.getChunkId() == RECIPIENT_EMAIL_ADDRESS.id) { - recipientEmailChunk = (StringChunk) chunk; - } else if (chunk.getChunkId() == RECIPIENT_SMTP_ADDRESS.id) { - recipientSMTPChunk = (StringChunk) chunk; - } else if (chunk.getChunkId() == DELIVERY_TYPE.id) { - deliveryTypeChunk = (StringChunk) chunk; - } else if (chunk instanceof PropertiesChunk) { - recipientProperties = (PropertiesChunk) chunk; + try { + if (chunk.getChunkId() == RECIPIENT_SEARCH.id) { + // TODO - parse + recipientSearchChunk = (ByteChunk) chunk; + } else if (chunk.getChunkId() == RECIPIENT_NAME.id) { + recipientDisplayNameChunk = (StringChunk) chunk; + } else if (chunk.getChunkId() == RECIPIENT_DISPLAY_NAME.id) { + recipientNameChunk = (StringChunk) chunk; + } else if (chunk.getChunkId() == RECIPIENT_EMAIL_ADDRESS.id) { + recipientEmailChunk = (StringChunk) chunk; + } else if (chunk.getChunkId() == RECIPIENT_SMTP_ADDRESS.id) { + recipientSMTPChunk = (StringChunk) chunk; + } else if (chunk.getChunkId() == DELIVERY_TYPE.id) { + deliveryTypeChunk = (StringChunk) chunk; + } else if (chunk instanceof PropertiesChunk) { + recipientProperties = (PropertiesChunk) chunk; + } + } catch (ClassCastException e) { + throw new IllegalArgumentException("ChunkId and type of chunk did not match, had id " + + chunk.getChunkId() + " and type of chunk: " + chunk.getClass(), e); } // And add to the main list -- cgit v1.2.3