Use DecodeLimit for decoding XCM messages (#605)

* Use DecodeLimit for decoding XCM messages

* Use decode_all_with_depth_limit in appropriate places

* Use decode_all while decoding byte vector

* cargo fmt
This commit is contained in:
Keith Yeung
2021-09-19 05:29:34 -07:00
committed by GitHub
parent 85bde07641
commit 1aab3349cc
34 changed files with 82 additions and 61 deletions
+7 -4
View File
@@ -21,7 +21,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode};
use codec::{Decode, DecodeLimit, Encode};
use cumulus_primitives_core::{relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler};
use frame_support::{
dispatch::Weight, traits::EnsureOrigin, weights::constants::WEIGHT_PER_MILLIS,
@@ -30,7 +30,7 @@ pub use pallet::*;
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;
use sp_std::{convert::TryFrom, prelude::*};
use xcm::{latest::prelude::*, VersionedXcm};
use xcm::{latest::prelude::*, VersionedXcm, MAX_XCM_DECODE_DEPTH};
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct ConfigData {
@@ -225,8 +225,11 @@ pub mod pallet {
data: &[u8],
) -> Result<Weight, (MessageId, Weight)> {
let id = sp_io::hashing::blake2_256(&data[..]);
let maybe_msg =
VersionedXcm::<T::Call>::decode(&mut &data[..]).map(Xcm::<T::Call>::try_from);
let maybe_msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
MAX_XCM_DECODE_DEPTH,
&mut &data[..],
)
.map(Xcm::<T::Call>::try_from);
match maybe_msg {
Err(_) => {
Self::deposit_event(Event::InvalidFormat(id));