mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-28 06:02:07 +00:00
validate trailing byte for i64
This commit is contained in:
BIN
res/cases/v1/err-leb-i64-too-long.wasm
Normal file
BIN
res/cases/v1/err-leb-i64-too-long.wasm
Normal file
Binary file not shown.
@ -40,6 +40,8 @@ impl Deserialize for VarUint32 {
|
|||||||
let mut shift = 0;
|
let mut shift = 0;
|
||||||
let mut u8buf = [0u8; 1];
|
let mut u8buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
|
if shift > 31 { return Err(Error::InvalidVarUint32); }
|
||||||
|
|
||||||
reader.read_exact(&mut u8buf)?;
|
reader.read_exact(&mut u8buf)?;
|
||||||
let b = u8buf[0] as u32;
|
let b = u8buf[0] as u32;
|
||||||
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint32)?;
|
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint32)?;
|
||||||
@ -91,6 +93,8 @@ impl Deserialize for VarUint64 {
|
|||||||
let mut shift = 0;
|
let mut shift = 0;
|
||||||
let mut u8buf = [0u8; 1];
|
let mut u8buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
|
if shift > 63 { return Err(Error::InvalidVarUint64); }
|
||||||
|
|
||||||
reader.read_exact(&mut u8buf)?;
|
reader.read_exact(&mut u8buf)?;
|
||||||
let b = u8buf[0] as u64;
|
let b = u8buf[0] as u64;
|
||||||
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint64)?;
|
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint64)?;
|
||||||
@ -349,6 +353,12 @@ impl Deserialize for VarInt64 {
|
|||||||
if (b >> 7) == 0 {
|
if (b >> 7) == 0 {
|
||||||
if shift < 64 && b & 0b0100_0000 == 0b0100_0000 {
|
if shift < 64 && b & 0b0100_0000 == 0b0100_0000 {
|
||||||
res |= (1i64 << shift).wrapping_neg();
|
res |= (1i64 << shift).wrapping_neg();
|
||||||
|
} else if shift >= 64 && b & 0b0100_0000 == 0b0100_0000 {
|
||||||
|
if (b | 0b1000_0000) as i8 != -1 {
|
||||||
|
return Err(Error::InvalidVarInt64);
|
||||||
|
}
|
||||||
|
} else if shift >= 64 && b != 0 {
|
||||||
|
return Err(Error::InvalidVarInt64);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user