From 27a616c3e96db4da9498e353afdd84f01d315b22 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 7 Dec 2022 12:42:09 +0100 Subject: [PATCH 1/2] chore: sync base58 with upstream --- base58/README.md | 3 +-- base58/base58.go | 4 ++++ base58/base58_test.go | 2 ++ base58/base58check.go | 2 +- base58/base58check_test.go | 11 +++++++---- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/base58/README.md b/base58/README.md index cc6e7295e..40dba64f1 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 8ee595671..bd0ea47cd 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 ff420f1f5..62b0e1412 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 7cdafeeec..402c3233f 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 6981122e5..d0183d23f 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") From 5952f5caf65230632c64c0b2a086bec509da6179 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 7 Dec 2022 12:54:51 +0100 Subject: [PATCH 2/2] trigger ci --- .github/workflows/go.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 15d585d52..1f015319a 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