Limit multibulk args count and fix integer type truncations#4010
Limit multibulk args count and fix integer type truncations#4010wufengwind wants to merge 1 commit into
Conversation
Add PROTO_MAX_MULTIBULK_LEN (1M) to prevent clients from causing OOM via excessive argv allocations. Use ztrymalloc/ztryrealloc so allocation failure returns a protocol error instead of crashing. Fix fragile implementation-defined behavior in parseMultibulk where unsigned subtraction overflow was cast to ssize_t. Replace with explicit size_t length checks. Add SIZE_MAX guard in rdbGenericLoadStringObject to reject RDB string lengths that exceed the platform's addressable size. Fix type truncation in sdsIncrLen assertions where ssize_t incr was cast to unsigned int on SDS_TYPE_32/16/8, losing bits on 64-bit platforms. Add sdsIncrLenAbs helper for correct sign handling. Signed-off-by: Feng Wu <wufengwufengwufeng@gmail.com>
📝 WalkthroughWalkthroughAdds ChangesToo-many-args multibulk protocol enforcement
Defensive size safety fixes in RDB and SDS
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/sds.c (1)
464-464: The assertion is functionally correct, but consider standardizing the condition for consistency.The SDS_TYPE_5 assertion uses
incr > 0while SDS_TYPE_8/16/32/64 useincr >= 0. Verification showssdsIncrLenis never called withincr == 0(all calls use positive or negative values), so the inconsistency doesn't cause a functional issue.However, the
> 0vs>= 0difference remains a code clarity concern. If standardizing the conditions is desired, change line 464 to useincr >= 0to match the other types. This is optional, as the current code works correctly in practice.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/sds.c` at line 464, The assertion at line 464 for SDS_TYPE_5 uses the condition `incr > 0` while the assertions for other SDS types (SDS_TYPE_8/16/32/64) use `incr >= 0`, creating an inconsistency in code clarity. To standardize the conditions across all types, modify the assertion at line 464 to change the `incr > 0` condition to `incr >= 0` to match the pattern used in the other SDS type assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/sds.c`:
- Line 464: The assertion at line 464 for SDS_TYPE_5 uses the condition `incr >
0` while the assertions for other SDS types (SDS_TYPE_8/16/32/64) use `incr >=
0`, creating an inconsistency in code clarity. To standardize the conditions
across all types, modify the assertion at line 464 to change the `incr > 0`
condition to `incr >= 0` to match the pattern used in the other SDS type
assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2fde5a94-a40b-4a2a-bf7d-79fa770cf1be
📒 Files selected for processing (5)
src/networking.csrc/rdb.csrc/sds.csrc/server.htests/unit/protocol.tcl
Add PROTO_MAX_MULTIBULK_LEN (1M) to prevent OOM from large argv allocations. Use ztrymalloc/ztryrealloc so allocation failure returns a protocol error instead of crashing.
Replace fragile unsigned subtraction overflow cast with explicit size_t checks in parseMultibulk.
Add SIZE_MAX guard in rdbGenericLoadStringObject for 32-bit platforms.
Fix sdsIncrLen type truncation where ssize_t was cast to unsigned int, losing upper bits on 64-bit.