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.
This commit is contained in:
Bastian Köcher
2022-06-22 11:02:59 +02:00
committed by GitHub
parent 4285ad916d
commit acc8cf6e4c
+5 -1
View File
@@ -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]