Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Validate encoding of extrinsics passed to runtime
  • Loading branch information
arkpar committed Jun 19, 2020
commit b66f1547d5edbdd4df562ca1c1573d18f509f15a
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion primitives/api/proc-macro/src/decl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
input: &I, error_desc: &'static str,
) -> std::result::Result<R, String>
{
<R as #crate_::Decode>::decode(
<R as #crate_::DecodeLimit>::decode_with_depth_limit(
#crate_::MAX_EXTRINSIC_DEPTH,
&mut &#crate_::Encode::encode(input)[..],
).map_err(|e| format!("{} {}", error_desc, e.what()))
}
Expand Down
5 changes: 4 additions & 1 deletion primitives/api/proc-macro/src/impl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ fn generate_impl_call(
Ok(
quote!(
#(
let #pnames : #ptypes = match #c_iter::Decode::decode(&mut #input) {
let #pnames : #ptypes = match #c_iter::DecodeLimit::decode_all_with_depth_limit(
#c_iter::MAX_EXTRINSIC_DEPTH,
&mut #input
) {
Ok(input) => input,
Err(e) => panic!("Bad input data provided to {}: {}", #fn_name_str, e.what()),
};
Expand Down
5 changes: 4 additions & 1 deletion primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ pub use sp_std::{slice, mem};
#[cfg(feature = "std")]
use sp_std::result;
#[doc(hidden)]
pub use codec::{Encode, Decode};
pub use codec::{Encode, Decode, DecodeLimit};
use sp_core::OpaqueMetadata;
#[cfg(feature = "std")]
use std::{panic::UnwindSafe, cell::RefCell};

/// Maximum nesting level for extrinsics.
pub const MAX_EXTRINSIC_DEPTH: u32 = 256;

/// Declares given traits as runtime apis.
///
/// The macro will create two declarations, one for using on the client side and one for using
Expand Down