Skip to content

socketshared: add maximum message size to avoid very large allocations#40050

Merged
benhillis merged 1 commit intomasterfrom
user/benhill/limit_message_size
Mar 31, 2026
Merged

socketshared: add maximum message size to avoid very large allocations#40050
benhillis merged 1 commit intomasterfrom
user/benhill/limit_message_size

Conversation

@benhillis
Copy link
Copy Markdown
Member

This change adds a maximum single message size of 4MiB to the socket helpers. This avoids a potentially huge (4GB) allocation from a malicious or buggy sender.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a hard cap on inbound socket message sizes in the shared socket receive helper to prevent excessively large allocations from malformed or malicious senders.

Changes:

  • Enforces a maximum single message size of 4 MiB in RecvMessage() before resizing the receive buffer.
  • Throws/returns an error on oversized messages to avoid attempting large allocations.

Comment thread src/shared/inc/socketshared.h
Comment thread src/shared/inc/socketshared.h
#if defined(_MSC_VER)
THROW_HR_MSG(E_UNEXPECTED, "Message size too large: %llu", MessageSize);
#elif defined(__GNUC__)
THROW_UNEXCEPTED();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be a good idea to LOG_ERROR() here, to make root causing this easier if it ever hits on the linux side

@benhillis benhillis merged commit 4417383 into master Mar 31, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants