From 9c4cbfcd67311b97a7aa7def48b315b2b7eda2c2 Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 6 Jan 2023 08:16:14 +0200 Subject: [PATCH] Length check in for extrinsic/call detect (#8703) * Length check in for extrinsic/call detect * s/lenght/length/ * Sprinkle in comments --- packages/page-extrinsics/src/Decoder.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/page-extrinsics/src/Decoder.tsx b/packages/page-extrinsics/src/Decoder.tsx index 7e78e76e8a..bf9aaf3442 100644 --- a/packages/page-extrinsics/src/Decoder.tsx +++ b/packages/page-extrinsics/src/Decoder.tsx @@ -60,12 +60,21 @@ function Decoder ({ className, defaultValue, setLast }: Props): React.ReactEleme let isCall = true; try { - // cater for an extrinsic input... - decoded = api.tx(hex); + // cater for an extrinsic input + const tx = api.tx(hex); + + // ensure that the full data matches here + assert(tx.toHex() === hex, 'Cannot decode data as extrinsic, length mismatch'); + + decoded = tx; extrinsicCall = api.createType('Call', decoded.method); isCall = false; } catch (e) { + // attempt to decode as Call extrinsicCall = api.createType('Call', hex); + + // ensure we used all bytes (as we did above) + assert(extrinsicCall.toHex() === hex, 'Unable to decode data as Call, length mismatch in supplied data'); } const { method, section } = api.registry.findMetaCall(extrinsicCall.callIndex);