Skip to content

Impose 512M maximum on RESP elements in RespReadUtils#1883

Merged
badrishc merged 3 commits into
mainfrom
users/kmontrose/imposeRespMaximums
Jun 17, 2026
Merged

Impose 512M maximum on RESP elements in RespReadUtils#1883
badrishc merged 3 commits into
mainfrom
users/kmontrose/imposeRespMaximums

Conversation

@kevin-montrose

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings June 16, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread test/standalone/Garnet.test/Resp/RespReadUtilsTests.cs
Comment thread libs/common/RespReadUtils.cs
@badrishc badrishc merged commit 1a3d3ee into main Jun 17, 2026
284 of 285 checks passed
@badrishc badrishc deleted the users/kmontrose/imposeRespMaximums branch June 17, 2026 05:08
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