@@ -192,6 +192,9 @@ use ::{
192192#[ allow( dead_code) ]
193193const LOG_TARGET : & str = "runtime::executive" ;
194194
195+ /// Maximum nesting level for extrinsics.
196+ pub const MAX_EXTRINSIC_DEPTH : u32 = 256 ;
197+
195198pub type CheckedOf < E , C > = <E as Checkable < C > >:: Checked ;
196199pub type CallOf < E , C > = <CheckedOf < E , C > as Applyable >:: Call ;
197200pub type OriginOf < E , C > = <CallOf < E , C > as Dispatchable >:: RuntimeOrigin ;
@@ -776,7 +779,13 @@ where
776779 let encoded = uxt. encode ( ) ;
777780 let encoded_len = encoded. len ( ) ;
778781 sp_tracing:: enter_span!( sp_tracing:: info_span!( "apply_extrinsic" ,
779- ext=?sp_core:: hexdisplay:: HexDisplay :: from( & encoded) ) ) ;
782+ ext=?sp_core:: hexdisplay:: HexDisplay :: from( & encoded) ) ) ;
783+
784+ let uxt = <Block :: Extrinsic as codec:: DecodeLimit >:: decode_all_with_depth_limit (
785+ MAX_EXTRINSIC_DEPTH ,
786+ & mut & encoded[ ..] ,
787+ )
788+ . expect ( "Decoding the encoded transaction works; qed" ) ;
780789
781790 // We use the dedicated `is_inherent` check here, since just relying on `Mandatory` dispatch
782791 // class does not capture optional inherents.
@@ -861,10 +870,16 @@ where
861870
862871 enter_span ! { sp_tracing:: Level :: TRACE , "validate_transaction" } ;
863872
864- let encoded_len = within_span ! { sp_tracing:: Level :: TRACE , "using_encoded" ;
865- uxt. using_encoded ( |d| d . len ( ) )
873+ let encoded = within_span ! { sp_tracing:: Level :: TRACE , "using_encoded" ;
874+ uxt. encode ( )
866875 } ;
867876
877+ let uxt = <Block :: Extrinsic as codec:: DecodeLimit >:: decode_all_with_depth_limit (
878+ MAX_EXTRINSIC_DEPTH ,
879+ & mut & encoded[ ..] ,
880+ )
881+ . map_err ( |_| InvalidTransaction :: Call ) ?;
882+
868883 let xt = within_span ! { sp_tracing:: Level :: TRACE , "check" ;
869884 uxt. check( & Default :: default ( ) )
870885 } ?;
@@ -879,7 +894,7 @@ where
879894
880895 within_span ! {
881896 sp_tracing:: Level :: TRACE , "validate" ;
882- xt. validate:: <UnsignedValidator >( source, & dispatch_info, encoded_len )
897+ xt. validate:: <UnsignedValidator >( source, & dispatch_info, encoded . len ( ) )
883898 }
884899 }
885900
0 commit comments