diff --git a/serialization/HDWallet/HDWallet.go b/serialization/HDWallet/HDWallet.go index e539054..dc51047 100644 --- a/serialization/HDWallet/HDWallet.go +++ b/serialization/HDWallet/HDWallet.go @@ -158,7 +158,7 @@ func (hd *HDWallet) DerivePath(path string) (*HDWallet, error) { derived_wallet := hd.copy() for _, index := range strings.Split(strings.TrimLeft(path, "m/"), "/") { if strings.HasSuffix(index, "'") { - ind_val, err := strconv.Atoi(string(index[:len(index)-1])) + ind_val, err := strconv.ParseUint(string(index[:len(index)-1]), 10, 32) if err != nil { return nil, err @@ -167,7 +167,7 @@ func (hd *HDWallet) DerivePath(path string) (*HDWallet, error) { uint32(ind_val), true, ) } else { - ind_val, err := strconv.Atoi(index) + ind_val, err := strconv.ParseUint(index, 10, 32) if err != nil { return nil, err } @@ -200,7 +200,7 @@ func (hd *HDWallet) Derive(index uint32, hardened bool) *HDWallet { return &HDWallet{ RootXprivKey: hd.RootXprivKey, XPrivKey: derived_xprivkey, - Path: hd.Path + "/" + strconv.Itoa(int(index)), + Path: hd.Path + "/" + strconv.FormatUint(uint64(index), 10), Seed: hd.Seed, Mnemonic: hd.Mnemonic, Passphrase: hd.Passphrase, diff --git a/serialization/common.go b/serialization/common.go index bd40777..b1e243b 100644 --- a/serialization/common.go +++ b/serialization/common.go @@ -3,6 +3,7 @@ package serialization import ( "encoding/hex" "fmt" + "math" "reflect" "strconv" @@ -116,6 +117,9 @@ func (cb *CustomBytes) Int() (int, error) { if err != nil { return 0, err } + if value < math.MinInt || value > math.MaxInt { + return 0, fmt.Errorf("value out of int range") + } return int(value), nil } return 0, fmt.Errorf("not int")