Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ impl VarInt for u64 {
result |= (msb_dropped as u64) << shift;
shift += 7;

if b & MSB == 0 || shift > (9 * 7) {
success = b & MSB == 0;
if shift > (9 * 7) {
// BUGIFX: this check is required to ensure that we actually return `None` when `src` has a value that would overflow `u64`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • BUGFIX

success = *b < 2;
break;
} else if b & MSB == 0 {
success = true;
break;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/varint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ mod tests {
);
}

#[test]
fn test_decode_max_u64_plus_one() {
let max_vec_encoded = vec![0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02];
assert!(u64::decode_var(max_vec_encoded.as_slice()).is_none());
}

#[test]
fn test_encode_i64() {
assert_eq!((0 as i64).encode_var_vec(), (0 as u32).encode_var_vec());
Expand Down