From bfa4c7b2c39ec31fb35390565eb1c9f18f639343 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 7 Mar 2022 09:24:20 +0100 Subject: [PATCH] fix: out of range case in gas estimation (#596) (cherry picked from commit 3aa4b0f59949955a89e5ac15554f3f561f7a1cb4) (cherry picked from commit 153095f8da618ccbab71c1d62fe156225618073a) Co-authored-by: librelois --- client/rpc/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/rpc/src/lib.rs b/client/rpc/src/lib.rs index e9b956788d..0d07f033c5 100644 --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -221,9 +221,11 @@ pub fn error_on_execution_failure(reason: &ExitReason, data: &[u8]) -> Result<() // should contain a utf-8 encoded revert reason. if data.len() > 68 { let message_len = data[36..68].iter().sum::(); - let body: &[u8] = &data[68..68 + message_len as usize]; - if let Ok(reason) = std::str::from_utf8(body) { - message = format!("{} {}", message, reason.to_string()); + if data.len() >= 68 + message_len as usize { + let body: &[u8] = &data[68..68 + message_len as usize]; + if let Ok(reason) = std::str::from_utf8(body) { + message = format!("{} {}", message, reason.to_string()); + } } } Err(Error {