From acc8cf6e4c7f75043449ec5090035fe370ab7abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 22 Jun 2022 11:02:59 +0200 Subject: [PATCH] WrapperOpaque: Use `decode_all` to decode from the `Vec` (#11726) This ensures that there isn't any extra data attached that isn't used. --- substrate/frame/support/src/traits/misc.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/src/traits/misc.rs b/substrate/frame/support/src/traits/misc.rs index 1f0ba1e769..ccbb47909d 100644 --- a/substrate/frame/support/src/traits/misc.rs +++ b/substrate/frame/support/src/traits/misc.rs @@ -745,7 +745,7 @@ impl Encode for WrapperOpaque { impl Decode for WrapperOpaque { fn decode(input: &mut I) -> Result { - Ok(Self(T::decode(&mut &>::decode(input)?[..])?)) + Ok(Self(T::decode_all(&mut &>::decode(input)?[..])?)) } fn skip(input: &mut I) -> Result<(), codec::Error> { @@ -967,6 +967,10 @@ mod test { 2usize.pow(14) - 1 + 2 ); assert_eq!(>::max_encoded_len(), 2usize.pow(14) + 4); + + let data = 4u64; + // Ensure that we check that the `Vec` is consumed completly on decode. + assert!(WrapperOpaque::::decode(&mut &data.encode().encode()[..]).is_err()); } #[test]