Limit nested container depth in Redis reply and AMF parsers#3344
Open
wwbmmm wants to merge 2 commits into
Open
Limit nested container depth in Redis reply and AMF parsers#3344wwbmmm wants to merge 2 commits into
wwbmmm wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds configurable maximum nesting-depth limits to the Redis reply and AMF parsers to prevent excessively deep inputs from consuming too much call stack during parsing.
Changes:
- Add
redis_max_reply_depthand enforce it during recursive Redis array reply parsing. - Add
amf_max_depthand enforce it during recursive AMF object/array parsing. - Add regression tests for over-limit nested Redis arrays and AMF strict arrays.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/brpc_rtmp_unittest.cpp | Adds a scoped override for amf_max_depth and a regression test for deeply nested AMF strict arrays. |
| test/brpc_redis_unittest.cpp | Adds a scoped override for redis_max_reply_depth and a regression test for deeply nested Redis array replies. |
| src/brpc/redis_reply.h | Adds a private depth-tracking overload for RedisReply::ConsumePartialIOBuf. |
| src/brpc/redis_reply.cpp | Defines redis_max_reply_depth and enforces the limit during recursive array parsing. |
| src/brpc/amf.cpp | Defines amf_max_depth and enforces it in recursive AMF object/array parsing helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
What problem does this PR solve?
Issue Number: null
Problem Summary:
Redis replies and AMF payloads can contain nested container values. The parsers previously bounded per-container allocation sizes, but did not bound nesting depth. Very deep inputs could therefore consume excessive call stack while parsing.
What is changed and the side effects?
Changed:
redis_max_reply_depthto limit nested Redis array replies.amf_max_depthto limit nested AMF objects and arrays.Side effects:
Check List: