cap simple string length in RedisReply::ConsumePartialIOBuf#3404
Open
ubeddulla wants to merge 1 commit into
Open
cap simple string length in RedisReply::ConsumePartialIOBuf#3404ubeddulla wants to merge 1 commit into
ubeddulla wants to merge 1 commit into
Conversation
Signed-off-by: ubeddulla khan <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens Redis reply parsing in brpc by enforcing the existing redis_max_allocation_size limit for Redis simple-string (+) and error (-) replies, preventing oversized payloads from overflowing internal length bookkeeping and leading to out-of-bounds reads.
Changes:
- Add a max-allocation-size cap for simple-string and error replies in
RedisReply::ConsumePartialIOBuf. - Add regression tests covering oversized simple-string and error replies alongside existing allocation-limit tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/brpc/redis_reply.cpp |
Adds allocation-size enforcement for +/- reply parsing. |
test/brpc_redis_unittest.cpp |
Adds new test cases to ensure oversized +/- replies are rejected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+144
to
+148
| if (len > (size_t)FLAGS_redis_max_allocation_size) { | ||
| LOG(ERROR) << "simple string exceeds max allocation size! max=" | ||
| << FLAGS_redis_max_allocation_size << ", actually=" << len; | ||
| return PARSE_ERROR_ABSOLUTELY_WRONG; | ||
| } |
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.
The simple-string ('+') and error ('-') branch of RedisReply::ConsumePartialIOBuf never bounds the payload length against redis_max_allocation_size, unlike the bulk-string ('$') and array ('*') branches in the same function which both cap it. A server returning a simple string of 2^31 bytes or more truncates the length into the signed int _length, and c_str()/data()/Print()/SerializeTo() then take the small-string path for the negative value and read past the 16-byte inline buffer. Cap it the same way the sibling branches already do, and add a regression test next to the existing bulk-string and array limit checks.