diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 15d585d5..1f015319 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,12 +1,14 @@ name: Build and Test -on: [push, pull_request] +on: + pull_request: + push: jobs: build: name: Go CI runs-on: ubuntu-latest steps: - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.19 - name: Check out source diff --git a/base58/README.md b/base58/README.md index cc6e7295..40dba64f 100644 --- a/base58/README.md +++ b/base58/README.md @@ -1,7 +1,6 @@ base58 ========== -[![Build Status](http://img.shields.io/travis/cosmos/btcutil.svg)](https://travis-ci.org/cosmos/btcutil) [![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org) [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/cosmos/btcutil/base58) @@ -14,7 +13,7 @@ A comprehensive suite of tests is provided to ensure proper functionality. ## Installation and Updating ```bash -$ go get -u github.com/cosmos/btcutil/base58 +go get -u github.com/cosmos/btcutil/base58 ``` ## Examples diff --git a/base58/base58.go b/base58/base58.go index 8ee59567..bd0ea47c 100644 --- a/base58/base58.go +++ b/base58/base58.go @@ -55,6 +55,10 @@ func Decode(b string) []byte { total := uint64(0) for _, v := range t[:n] { + if v > 255 { + return []byte("") + } + tmp := b58[v] if tmp == 255 { return []byte("") diff --git a/base58/base58_test.go b/base58/base58_test.go index ff420f1f..62b0e141 100644 --- a/base58/base58_test.go +++ b/base58/base58_test.go @@ -43,6 +43,8 @@ var invalidStringTests = []struct { {"4kl8", ""}, {"0OIl", ""}, {"!@#$%^&*()-_=+~`", ""}, + {"abcd\xd80", ""}, + {"abcd\U000020BF", ""}, } var hexTests = []struct { diff --git a/base58/base58check.go b/base58/base58check.go index 7cdafeee..402c3233 100644 --- a/base58/base58check.go +++ b/base58/base58check.go @@ -28,7 +28,7 @@ func checksum(input []byte) (cksum [4]byte) { func CheckEncode(input []byte, version byte) string { b := make([]byte, 0, 1+len(input)+4) b = append(b, version) - b = append(b, input[:]...) + b = append(b, input...) cksum := checksum(b) b = append(b, cksum[:]...) return Encode(b) diff --git a/base58/base58check_test.go b/base58/base58check_test.go index 6981122e..d0183d23 100644 --- a/base58/base58check_test.go +++ b/base58/base58check_test.go @@ -37,11 +37,14 @@ func TestBase58Check(t *testing.T) { // test decoding res, version, err := base58.CheckDecode(test.out) - if err != nil { + switch { + case err != nil: t.Errorf("CheckDecode test #%d failed with err: %v", x, err) - } else if version != test.version { + + case version != test.version: t.Errorf("CheckDecode test #%d failed: got version: %d want: %d", x, version, test.version) - } else if string(res) != test.in { + + case string(res) != test.in: t.Errorf("CheckDecode test #%d failed: got: %s want: %s", x, res, test.in) } } @@ -56,7 +59,7 @@ func TestBase58Check(t *testing.T) { // bytes are missing). testString := "" for len := 0; len < 4; len++ { - testString = testString + "x" + testString += "x" _, _, err = base58.CheckDecode(testString) if err != base58.ErrInvalidFormat { t.Error("Checkdecode test failed, expected ErrInvalidFormat")