add more for i32

This commit is contained in:
NikVolf 2018-03-19 02:33:58 +03:00
parent 4d4dfb621e
commit 59b61c6ef6
2 changed files with 26 additions and 0 deletions

Binary file not shown.

View File

@ -287,6 +287,14 @@ impl Deserialize for VarInt32 {
if (b >> 7) == 0 { if (b >> 7) == 0 {
if shift < 32 && b & 0b0100_0000 == 0b0100_0000 { if shift < 32 && b & 0b0100_0000 == 0b0100_0000 {
res |= (1i32 << shift).wrapping_neg(); res |= (1i32 << shift).wrapping_neg();
} else if shift >= 32 && b & 0b0100_0000 == 0b0100_0000 {
if (!(b | 0b1000_0000)).leading_zeros() < 4 {
return Err(Error::InvalidVarInt32);
}
} else if shift >= 32 && b & 0b0100_0000 == 0 {
if b.leading_zeros() < 4 {
return Err(Error::InvalidVarInt32);
}
} }
break; break;
} }
@ -758,6 +766,24 @@ mod tests {
); );
} }
#[test]
fn varint64_bad_extended() {
let res = deserialize_buffer::<VarInt64>(&[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x6f][..]);
assert!(res.is_err());
}
#[test]
fn varint32_bad_extended() {
let res = deserialize_buffer::<VarInt32>(&[0x80, 0x80, 0x80, 0x80, 0x6f][..]);
assert!(res.is_err());
}
#[test]
fn varint32_bad_extended2() {
let res = deserialize_buffer::<VarInt32>(&[0x80, 0x80, 0x80, 0x80, 0x41][..]);
assert!(res.is_err());
}
#[test] #[test]
fn varint64_max() { fn varint64_max() {
varint64_serde_test( varint64_serde_test(