Skip to content

cap simple string length in RedisReply::ConsumePartialIOBuf#3404

Open
ubeddulla wants to merge 1 commit into
apache:masterfrom
ubeddulla:redis-simple-string-length-cap
Open

cap simple string length in RedisReply::ConsumePartialIOBuf#3404
ubeddulla wants to merge 1 commit into
apache:masterfrom
ubeddulla:redis-simple-string-length-cap

Conversation

@ubeddulla

Copy link
Copy Markdown
Contributor

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.

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 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 thread src/brpc/redis_reply.cpp
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;
}
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