From bdd406754d94179fbcc97e0c6ee241d3361ae6b7 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Fri, 23 Feb 2024 15:45:18 +0000 Subject: [PATCH] avoid a panic in case we try decoding naff bytes --- 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)