Skip to content

Consuming a large amount of memory when unpacking huge Array and Map unexpectedly #657

Open

Description

@napo0703

There is a problem of unexpectedly consuming a large amount of memory when unpacking huge Array and Map.
For example, this code may causes an OutOfMemoryError.

    public static void unpackHugeArray()
            throws IOException
    {
        MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
        packer.packArrayHeader(2147483647);
        packer.close();

        byte[] packedData = packer.toByteArray();
        MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(packedData);
        unpacker.unpackValue();  // Caused by: java.lang.OutOfMemoryError
        unpacker.close();
    }

Activity

  1. Marcono1234 commented on Oct 29, 2026

    @Marcono1234

    Maybe related to GHSA-cw39-r4h6-8j3x / daa2ea6.

    As fix could have a threshold (similar to GRADUAL_ALLOCATION_THRESHOLD, but probably with a lower value), and if the length (respectively for map length * 2 (accounting for overflow)) is larger, collect in a new ArrayList<>(THRESHOLD) and then eventually call ArrayList#toArray?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions