Skip to content

Commit ee978d7

Browse files
committed
fix(resp): replace wrapping arithmetic with checked operations in parse_integer
Use checked_mul/checked_add instead of wrapping_mul/wrapping_add to detect integer overflow in the RESP integer parser. Previously, a bulk string length exceeding i64::MAX was silently wrapped, which could lead to incorrect parsing if rustis is used as a proxy with untrusted input.
1 parent f113d54 commit ee978d7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/resp/resp_frame_parser.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ impl<'a> RespFrameParser<'a> {
253253
let b = slice[i];
254254
match b {
255255
b'0'..=b'9' => {
256-
// n = n * 10 + (b - b'0')
257-
n = n.wrapping_mul(10).wrapping_add((b - b'0') as i64);
256+
n = n
257+
.checked_mul(10)
258+
.and_then(|n| n.checked_add((b - b'0') as i64))
259+
.ok_or(Error::Client(ClientError::CannotParseInteger))?;
258260
i += 1;
259261
}
260262
b'\r' => match slice.get(i + 1) {

0 commit comments

Comments
 (0)