From 153095f8da618ccbab71c1d62fe156225618073a Mon Sep 17 00:00:00 2001 From: librelois Date: Thu, 3 Feb 2022 17:24:24 +0100 Subject: [PATCH] fix: out of range case in gas estimation (cherry picked from commit 3aa4b0f59949955a89e5ac15554f3f561f7a1cb4) --- 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 7e5d3f9591..63bf6b1c3b 100644 --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -229,9 +229,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 {