File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ use sp_blockchain::{BlockStatus, HeaderBackend};
3131use sp_runtime:: {
3232 generic:: BlockId ,
3333 traits:: { BlakeTwo256 , Block as BlockT } ,
34+ SaturatedConversion ,
3435} ;
3536
3637use fc_rpc_core:: types:: * ;
@@ -688,13 +689,19 @@ pub fn error_on_execution_failure(reason: &ExitReason, data: &[u8]) -> Result<()
688689 ) )
689690 }
690691 ExitReason :: Revert ( _) => {
692+ const LEN_START : usize = 36 ;
693+ const MESSAGE_START : usize = 68 ;
694+
691695 let mut message = "VM Exception while processing transaction: revert" . to_string ( ) ;
692696 // A minimum size of error function selector (4) + offset (32) + string length (32)
693697 // should contain a utf-8 encoded revert reason.
694- if data. len ( ) > 68 {
695- let message_len = data[ 36 ..68 ] . iter ( ) . sum :: < u8 > ( ) ;
696- if data. len ( ) >= 68 + message_len as usize {
697- let body: & [ u8 ] = & data[ 68 ..68 + message_len as usize ] ;
698+ if data. len ( ) > MESSAGE_START {
699+ let message_len =
700+ U256 :: from ( & data[ LEN_START ..MESSAGE_START ] ) . saturated_into :: < usize > ( ) ;
701+ let message_end = MESSAGE_START . saturating_add ( message_len) ;
702+
703+ if data. len ( ) >= message_end {
704+ let body: & [ u8 ] = & data[ MESSAGE_START ..message_end] ;
698705 if let Ok ( reason) = std:: str:: from_utf8 ( body) {
699706 message = format ! ( "{} {}" , message, reason) ;
700707 }
You can’t perform that action at this time.
0 commit comments