mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-04-25 07:12:15 +00:00
also limit for unsigned
This commit is contained in:
parent
59b61c6ef6
commit
c2184421f1
BIN
res/cases/v1/err-leb-i32-too-long-2.wasm
Normal file
BIN
res/cases/v1/err-leb-i32-too-long-2.wasm
Normal file
Binary file not shown.
BIN
res/cases/v1/err-leb-u32-too-long.wasm
Normal file
BIN
res/cases/v1/err-leb-u32-too-long.wasm
Normal file
Binary file not shown.
@ -1 +1 @@
|
|||||||
Subproject commit c538faa43217146f458b9bc2d4b704d0a4d80963
|
Subproject commit 8958a44bf8b3dbf9e48dd1c44ee566e8bf682abe
|
@ -47,6 +47,9 @@ impl Deserialize for VarUint32 {
|
|||||||
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint32)?;
|
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint32)?;
|
||||||
shift += 7;
|
shift += 7;
|
||||||
if (b >> 7) == 0 {
|
if (b >> 7) == 0 {
|
||||||
|
if shift >= 32 && (b as u8).leading_zeros() < 4 {
|
||||||
|
return Err(Error::InvalidVarInt32);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,6 +103,9 @@ impl Deserialize for VarUint64 {
|
|||||||
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint64)?;
|
res |= (b & 0x7f).checked_shl(shift).ok_or(Error::InvalidVarUint64)?;
|
||||||
shift += 7;
|
shift += 7;
|
||||||
if (b >> 7) == 0 {
|
if (b >> 7) == 0 {
|
||||||
|
if shift >= 64 && (b as u8).leading_zeros() < 7 {
|
||||||
|
return Err(Error::InvalidVarInt64);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,11 +294,11 @@ impl Deserialize for VarInt32 {
|
|||||||
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 {
|
} else if shift >= 32 && b & 0b0100_0000 == 0b0100_0000 {
|
||||||
if (!(b | 0b1000_0000)).leading_zeros() < 4 {
|
if (!(b | 0b1000_0000)).leading_zeros() < 5 {
|
||||||
return Err(Error::InvalidVarInt32);
|
return Err(Error::InvalidVarInt32);
|
||||||
}
|
}
|
||||||
} else if shift >= 32 && b & 0b0100_0000 == 0 {
|
} else if shift >= 32 && b & 0b0100_0000 == 0 {
|
||||||
if b.leading_zeros() < 4 {
|
if b.leading_zeros() < 5 {
|
||||||
return Err(Error::InvalidVarInt32);
|
return Err(Error::InvalidVarInt32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -828,6 +834,24 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn varuint32_too_long_trailing() {
|
||||||
|
assert!(
|
||||||
|
deserialize_buffer::<VarUint32>(
|
||||||
|
&[0xff, 0xff, 0xff, 0xff, 0x7f][..],
|
||||||
|
).is_err()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn varuint64_too_long_trailing() {
|
||||||
|
assert!(
|
||||||
|
deserialize_buffer::<VarUint64>(
|
||||||
|
&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04][..],
|
||||||
|
).is_err()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn varint32_min() {
|
fn varint32_min() {
|
||||||
varint32_serde_test(
|
varint32_serde_test(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user