Skip to content

Bucket.keyEquals() may throw an underflow exception #20146

@artemananiev

Description

@artemananiev

Here is an example:

2025-07-11 20:09:53.121 ERROR 161  DispatchProcessor - Possibly CATASTROPHIC failure - exception thrown while handling dispatch
java.nio.BufferUnderflowException
        at com.hedera.pbj.runtime.io.buffer.Bytes.getByte(Bytes.java:511)
        at com.swirlds.merkledb.files.hashmap.Bucket.keyEquals(Bucket.java:488)
        at com.swirlds.merkledb.files.hashmap.Bucket.findEntry(Bucket.java:465)
        at com.swirlds.merkledb.files.hashmap.Bucket.findValue(Bucket.java:188)
        at com.swirlds.merkledb.files.hashmap.HalfDiskHashMap.get(HalfDiskHashMap.java:875)
        ...

Bucket.keyEquals() is very straightforward:

    private boolean keyEquals(final long pos, final int size, final Bytes key) {
        for (int i = 0; i < size; i++) {
            if (bucketData.getByte(pos + i) != key.getByte(i)) {
                return false;
            }
        }
        return true;
    }

This method checks if a bucket entry at the given pos matches the given key. Entry hash code is the same as key hash code, but entry may be longer than the key. In this case, the loop above throws a buffer underflow exception.

Metadata

Metadata

Assignees

Labels

BugAn error that causes the feature to behave differently than what was expected based on design.PlatformTickets pertaining to the platformPlatform Data StructuresPlatform Virtual Map

Type

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions