gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
943 stars 267 forks source link

gagliardetto/binary have some problem #95

Closed yangyangpig closed 2 years ago

yangyangpig commented 2 years ago

show code:

mintAccount, err := mintInstance.SolanaClient.RPC.GetAccountInfo(context.Background(), metadataPubkey) if err != nil { panic(err) } var metdataData *tokenmetadata.Metadata if err := bin.NewBinDecoder(mintAccount.Value.Data.GetBinary()).Decode(&metdataData); err != nil { log.Errorf("NewBinDecoder error %+v", err) return }


error info:

--- FAIL: TestGetProgramAccounts (35.10s) panic: runtime error: makeslice: len out of range [recovered] panic: runtime error: makeslice: len out of range

goroutine 52 [running]: testing.tRunner.func1.2({0x102576920, 0x1025eb460}) /usr/local/go/src/testing/testing.go:1209 +0x258 testing.tRunner.func1(0x1400068ab60) /usr/local/go/src/testing/testing.go:1212 +0x284 panic({0x102576920, 0x1025eb460}) /usr/local/go/src/runtime/panic.go:1038 +0x21c github.com/gagliardetto/binary.readNBytes(0x676e696b00000020, {0x1025f4448, 0x14000665920}) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder.go:273 +0x38 github.com/gagliardetto/binary.(Decoder).ReadNBytes(...) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder.go:286 github.com/gagliardetto/binary.(Decoder).ReadRustString(0x14000665920) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder.go:548 +0x74 github.com/gagliardetto/binary.(Decoder).decodeBin(0x14000665920, {0x1025558c0, 0x14000184048, 0x16}, 0x0) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder_bin.go:89 +0x10f4 github.com/gagliardetto/binary.(Decoder).decodeWithOptionBin(0x14000665920, {0x1025558c0, 0x14000184048}, 0x0) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder_bin.go:36 +0x1a8 github.com/gagliardetto/binary.(Decoder).Decode(0x14000665920, {0x1025558c0, 0x14000184048}) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder.go:121 +0xc4 github.com/gagliardetto/metaplex-go/clients/token-metadata.(Data).UnmarshalWithDecoder(0x14000184048, 0x14000665920) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/metaplex-go@v0.2.1/clients/token-metadata/accounts.go:113 +0x40 github.com/gagliardetto/binary.(Decoder).decodeBin(0x14000665920, {0x1025786a0, 0x14000184048, 0x16}, 0x0) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder_bin.go:83 +0x628 github.com/gagliardetto/binary.(Decoder).decodeWithOptionBin(0x14000665920, {0x1025786a0, 0x14000184048}, 0x0) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder_bin.go:36 +0x1a8 github.com/gagliardetto/binary.(Decoder).Decode(0x14000665920, {0x1025786a0, 0x14000184048}) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder.go:121 +0xc4 github.com/gagliardetto/metaplex-go/clients/token-metadata.(Metadata).UnmarshalWithDecoder(0x14000184000, 0x14000665920) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/metaplex-go@v0.2.1/clients/token-metadata/accounts.go:690 +0xdc github.com/gagliardetto/binary.(Decoder).decodeBin(0x14000665920, {0x10254eb80, 0x140004c45e0, 0x16}, 0x0) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder_bin.go:83 +0x628 github.com/gagliardetto/binary.(Decoder).decodeWithOptionBin(0x14000665920, {0x10254eb80, 0x140004c45e0}, 0x0) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder_bin.go:36 +0x1a8 github.com/gagliardetto/binary.(Decoder).Decode(0x14000665920, {0x10254eb80, 0x140004c45e0}) /Users/davidliu/go/pkg/mod/github.com/gagliardetto/binary@v0.6.1/decoder.go:121 +0xc4 azeroth.io/northrend/kafu/solana/nft.TestGetProgramAccounts(0x1400068ab60) /Users/davidliu/company/ttc/northrend-mono/northrend/kafu/solana/nft/mint_test.go:115 +0xea0 testing.tRunner(0x1400068ab60, 0x1025e95c0) /usr/local/go/src/testing/testing.go:1259 +0xfc created by testing.(T).Run /usr/local/go/src/testing/testing.go:1306 +0x328 exit status 2


This question has puzzled me for a long time. Please help me 😊

riptl commented 2 years ago

cc @gagliardetto I'm planning to fix this today. The bug here is that reflect.MakeSlice is called without prior bounds checks. (Bounds checks are only implied as the slice is populated)

gagliardetto commented 2 years ago

cc @gagliardetto I'm planning to fix this today. The bug here is that reflect.MakeSlice is called without prior bounds checks. (Bounds checks are only implied as the slice is populated)

Thank you very much!