Skip to content

Additional overflow protection for MAP/ATTR#292

Merged
michael-grunder merged 1 commit intovalkey-io:mainfrom
michael-grunder:fix-map-overflow
Mar 11, 2026
Merged

Additional overflow protection for MAP/ATTR#292
michael-grunder merged 1 commit intovalkey-io:mainfrom
michael-grunder:fix-map-overflow

Conversation

@michael-grunder
Copy link
Copy Markdown
Collaborator

There is already overflow protection for multibulk elements but the new RESP3 MAP and ATTR types subsequently double the count.

This meant that a malicious or erroneous count of LLONG_MAX / 2 + 1 would end up overflowing when maxelements = 0.

@michael-grunder michael-grunder requested a review from bjosv March 10, 2026 15:51
@michael-grunder
Copy link
Copy Markdown
Collaborator Author

The check can be done more concisely but it seemed that clarity was more important.

Copy link
Copy Markdown
Collaborator

@bjosv bjosv left a comment

Choose a reason for hiding this comment

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

Nice, good finding! A pesky times two..
Maybe line 540 will be the first protection?

Comment thread tests/client_test.c Outdated
There is already overflow protection for multibulk `elements` but the
new RESP3 `MAP` and `ATTR` types subsequently double the count.

This meant that a malicious or erroneous count of `LLONG_MAX / 2 + 1`
would end up overflowing when maxelements = 0.

Signed-off-by: michael-grunder <michael.grunder@gmail.com>
@michael-grunder
Copy link
Copy Markdown
Collaborator Author

Maybe line 540 will be the first protection?

We can put all of the checks on 540 but this seemed easier to reason about.

Comment thread src/read.c
@bjosv
Copy link
Copy Markdown
Collaborator

bjosv commented Mar 11, 2026

Yes, current state is easy to read. I think it's good to go 👍

@michael-grunder michael-grunder merged commit 0fa8098 into valkey-io:main Mar 11, 2026
48 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.

2 participants