Skip to content

Commit e156a22

Browse files
authored
fix(prost-codec): checked addition in Codec::decode
If the length of the varint at the beginning of a decoded value plus the payload length reported within it overflows, we can cheat the test for the remaining buffer length, and the `src.split_to(message_length)` call will then cause a panic as `message_length` is a very large value. Pull-Request: #6467.
1 parent 969b707 commit e156a22

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

misc/prost-codec/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ where
8181
let varint_length = src.len() - remaining.len();
8282

8383
// Ensure we can read an entire message.
84-
if src.len() < (message_length + varint_length) {
84+
if message_length
85+
.checked_add(varint_length)
86+
.is_none_or(|total_length| src.len() < total_length)
87+
{
8588
return Ok(None);
8689
}
8790

0 commit comments

Comments
 (0)