Skip to content
Snippets Groups Projects
Commit acc8cf6e authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

WrapperOpaque: Use `decode_all` to decode from the `Vec<u8>` (#11726)

This ensures that there isn't any extra data attached that isn't used.
parent 4285ad91
No related merge requests found
......@@ -745,7 +745,7 @@ impl<T: Encode> Encode for WrapperOpaque<T> {
impl<T: Decode> Decode for WrapperOpaque<T> {
fn decode<I: Input>(input: &mut I) -> Result<Self, codec::Error> {
Ok(Self(T::decode(&mut &<Vec<u8>>::decode(input)?[..])?))
Ok(Self(T::decode_all(&mut &<Vec<u8>>::decode(input)?[..])?))
}
fn skip<I: Input>(input: &mut I) -> Result<(), codec::Error> {
......@@ -967,6 +967,10 @@ mod test {
2usize.pow(14) - 1 + 2
);
assert_eq!(<WrapperOpaque<[u8; 2usize.pow(14)]>>::max_encoded_len(), 2usize.pow(14) + 4);
let data = 4u64;
// Ensure that we check that the `Vec<u8>` is consumed completly on decode.
assert!(WrapperOpaque::<u32>::decode(&mut &data.encode().encode()[..]).is_err());
}
#[test]
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment