wwbmmm opened a new pull request, #3722:
URL: https://github.com/apache/brpc/pull/3722

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Problem Summary:
   
   `-redis_max_allocation_size` is documented as the maximum memory allocation 
size in bytes for a single redis request or reply, but the redis parsers only 
applied it to each bulk string / array descriptor individually. A RESP command 
array (`RedisCommandParser`) or a reply array 
(`RedisReply::ConsumePartialIOBuf`) carrying several individually permitted 
bulk/simple strings therefore parses successfully while its total arena 
allocation exceeds the cap. On the server path the already parsed arguments 
stay in the connection arena while the rest of the command is pending, so 
concurrent peers can compound the memory use.
   
   ### What is changed and the side effects?
   
   Changed:
   - `RedisCommandParser` now tracks the string payload bytes already parsed 
for the current command in `_used_bytes` and rejects a bulk string that would 
make the total exceed `-redis_max_allocation_size`. The counter survives 
partial reads and is reset when the command completes. The `_args` descriptors 
remain bounded by the existing array-count check.
   - `RedisReply` charges bulk strings and long simple strings to the per-reply 
budget that already accounts for array descriptors, so a reply tree draws from 
one budget and the accounting keeps being saved/restored across parsing 
suspension.
   - Added unit tests for both parsers: accumulated strings above the cap are 
rejected (including when the offending string only arrives after a resume), and 
messages whose strings add up to exactly the cap still parse.
   
   Side effects:
   - Performance effects: one extra 64-bit add and compare per bulk/string 
allocation on the parsing path, negligible.
   
   - Breaking backward compatibility: a request or reply whose strings add up 
to more than `-redis_max_allocation_size` is now rejected, while it used to 
parse. This matches the documented meaning of the flag; deployments that 
intentionally accept larger redis messages need to raise the flag.
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   
   ---
   🤖 This PR was automatically created by brpc-oncall


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to