From 70d56dc62f29db51501f78ca1b89ec1cb9843f61 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Sat, 24 Feb 2024 10:48:39 +0000 Subject: [PATCH] avoid a panic in case we try decoding naff bytes (#1444) --- subxt/src/backend/legacy/rpc_methods.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subxt/src/backend/legacy/rpc_methods.rs b/subxt/src/backend/legacy/rpc_methods.rs index b227694b55..982faf9a7e 100644 --- a/subxt/src/backend/legacy/rpc_methods.rs +++ b/subxt/src/backend/legacy/rpc_methods.rs @@ -535,6 +535,13 @@ impl DryRunResultBytes { // dryRun returns an ApplyExtrinsicResult, which is basically a // `Result, TransactionValidityError>`. let bytes = self.0; + + // We expect at least 2 bytes. In case we got a naff response back (or + // manually constructed this struct), just error to avoid a panic: + if bytes.len() < 2 { + return Err(crate::Error::Unknown(bytes)); + } + if bytes[0] == 0 && bytes[1] == 0 { // Ok(Ok(())); transaction is valid and executed ok Ok(DryRunResult::Success)