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
This commit is contained in:
Dominik Stadler 2023-08-12 17:37:14 +00:00
parent 733d3d10ea
commit 9ae14ef6f0
3 changed files with 21 additions and 16 deletions

View File

@ -187,7 +187,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
}
/** Holds all the chunks that were found. */
private List<Chunk> allChunks = new ArrayList<>();
private final List<Chunk> allChunks = new ArrayList<>();
@Override
public Map<MAPIProperty, List<PropertyValue>> getProperties() {
@ -212,6 +212,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
*/
@Override
public void record(Chunk chunk) {
try {
if (chunk.getChunkId() == RECIPIENT_SEARCH.id) {
// TODO - parse
recipientSearchChunk = (ByteChunk) chunk;
@ -228,6 +229,10 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
} 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
allChunks.add(chunk);

Binary file not shown.