Skip to content

SignalR Java client allocates binary values before validating MessagePack lengths #70259

Description

@BrennanConroy

Is there an existing issue for this?

  • I have searched the existing issues.

Describe the bug

MessagePackHubProtocol.java reads a binary value's length prefix and allocates an array of that size before checking whether the message contains the declared number of bytes:

length = unpacker.unpackBinaryHeader();
byte[] binaryValue = new byte[length];
unpacker.readPayload(binaryValue);

A small, malformed message can therefore cause an allocation much larger than its actual payload before parsing detects the missing data.

parseMessages validates the outer SignalR message length, but that does not validate length prefixes embedded within the MessagePack body. Its final consumed-byte check also occurs after the allocation.

Expected Behavior

Validate embedded lengths against the bytes remaining in the current SignalR message before allocating length-dependent buffers. Malformed or truncated values should be rejected without allocating their declared size.

Steps To Reproduce

Construct a SignalR invocation containing a binary argument whose MessagePack length prefix declares substantially more bytes than are present. Set the outer SignalR frame length to match the actual encoded body, and parse it with a binder expecting a byte[] argument.

The binary parsing branch allocates new byte[length] before readPayload discovers that the bytes are missing.

This reproduction is based on source inspection; it has not been executed.

Exceptions (if any)

The eventual exception depends on the declared length and available memory. No runtime exception output has been collected.

.NET Version

N/A — SignalR Java client.

Anything else?

The confirmed allocation site is the BINARY branch of readValue in MessagePackHubProtocol.java. Validation should respect the current message's boundary, not include bytes belonging to subsequent messages in the same buffer.

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

Metadata

Metadata

Labels

area-signalr

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions