Solnet icon indicating copy to clipboard operation
Solnet copied to clipboard

[Bug] InstructionDecoder.DecodeInstructions: Specified argument was out of the range of valid values. (Parameter 'offset')

Open JavinYang opened this issue 3 years ago • 1 comments

Describe the bug When I call InstructionDecoder.DecodeInstructions to parse 5vwPMat2ukA6SZpL4vWa5ty1W4WALreavXvPoUUDqtt4EHkfD7Kgyk5QPDxRVwH1yEsYK76tDZhoC83EKM2RAMMo an exception will be thrown

To Reproduce

static void Test()
{
        var rpcClient = Solnet.Rpc.ClientFactory.GetClient("https://rpc.ankr.com/solana");

        var t = rpcClient.GetTransaction("5vwPMat2ukA6SZpL4vWa5ty1W4WALreavXvPoUUDqtt4EHkfD7Kgyk5QPDxRVwH1yEsYK76tDZhoC83EKM2RAMMo");
        var res = t.Result;
        Solnet.Programs.InstructionDecoder.DecodeInstructions(res);
}

Additional context System.ArgumentOutOfRangeException: "Specified argument was out of the range of valid values. (Parameter 'offset')" at Solnet.Programs.Utilities.Deserialization.GetPubKey(ReadOnlySpan1 data, Int32 offset) in /Users/yjy/Documents/Code/CSharp/RomeChainServer/Solnet/src/Solnet.Programs/Utilities/Deserialization.cs:line 152\n at Solnet.Programs.TokenProgramData.DecodeSetAuthorityData(DecodedInstruction decodedInstruction, ReadOnlySpan1 data, IList1 keys, Byte[] keyIndices) in /Users/yjy/Documents/Code/CSharp/RomeChainServer/Solnet/src/Solnet.Programs/TokenProgramData.cs:line 305\n at Solnet.Programs.TokenProgram.Decode(ReadOnlySpan1 data, IList`1 keys, Byte[] keyIndices) in /Users/yjy/Documents/Code/CSharp/RomeChainServer/Solnet/src/Solnet.Programs/TokenProgram.cs:line 602\n at Solnet.Programs.InstructionDecoder.DecodeInstructions(TransactionMetaInfo txMetaInfo) in /Users/yjy/Documents/Code/CSharp/RomeChainServer/Solnet/src/Solnet.Programs/InstructionDecoder.cs:line 116\n at RomeChainServer.Program.Test() in /Users/yjy/Documents/Code/CSharp/RomeChainServer/RomeChainServer/Program.cs:line 351\n at RomeChainServer.Program.Main(String[] args) in /Users/yjy/Documents/Code/CSharp/RomeChainServer/RomeChainServer/Program.cs:67

The problem occurs Solana.Programs.Utilities.Deserialization.cs: 152 The above code will cause 3 times to enter the GetPubKey function, when entering the third time offset = 3 PublicKey. PublicKeyLength = 32 data. Length = 3 So the exception is thrown How should I fix this bug?

JavinYang avatar Nov 24 '22 13:11 JavinYang

2f6d8dc

Added patch to recent PR. Awaiting merge from @tiago18c @murlokito

BifrostTitan avatar Nov 24 '22 23:11 BifrostTitan