Impose 512M maximum on RESP elements in RespReadUtils#1883
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a hard upper bound (512MB, matching Redis’ default max bulk string size) for individual RESP bulk element lengths to avoid unsafe pointer arithmetic when parsing large length headers, and adds a regression test for oversized length rejection.
Changes:
- Introduced
RespReadUtils.MaxArgumentLengthBytes(512MB) as the shared maximum single-element length. - Enforced the maximum in multiple RESP bulk-string parsing helpers and in server
SessionParseState.Read. - Updated the client-side bulk string reader to apply the same maximum, and added unit tests for the new limit.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/standalone/Garnet.test/Resp/RespReadUtilsTests.cs | Adds a new test validating that oversized RESP bulk lengths are rejected across several parsing helpers. |
| libs/server/Resp/Parser/SessionParseState.cs | Rejects parsed bulk-string argument lengths that exceed MaxArgumentLengthBytes during server request parsing. |
| libs/common/RespReadUtils.cs | Defines MaxArgumentLengthBytes and applies it in several bulk-string parsing helpers to fail early on oversized lengths. |
| libs/client/RespReadResponseUtils.cs | Applies the same maximum length guard when reading bulk strings in the client response parser. |
badrishc
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are a number of places where we parse a length and then slam it into a pointer.
Generally this gets dicey with large numbers, and we don't actually expect requests where single elements are hundreds of megabytes to succeed. A reasonable limit is the Redis string max length, or 512 megabytes.
We may want to revisit this later to fail requests streams more gracefully, but for now this just blanket "returns false" if we're about to get in trouble.