From dc14acf9ef15f85828bfbc561ed9dd9d2a284885 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Sun, 11 Nov 2018 22:10:44 +0100 Subject: [PATCH] Release v0.14.1 (#244) * add contribution guidelines - minimal changes to ensure proto3 compat. for unsigned ints (int, int32, int64) * Add changes to decode ints, too * Delete outdated tests (covered by new table driven test) * Add overflow checks for int & int32 * prep release: update changelog * Make amino build on 32bit architectures (#242) * fix int overflows that happen on 32bit systems - explicitly type constant in time encoding - use math.MaxInt32 in int tests to seed the fuzzer * Add --concrete-name option to aminoscan --- CHANGELOG.md | 7 +++ CONTRIBUTING.md | 63 +++++++++++++++++++++++++++ cmd/{ => aminoscan}/aminoscan.go | 9 ++++ cmd/{ => aminoscan}/colors.go | 0 encoder.go | 11 +++-- tests/fuzz/binary/init-corpus/main.go | 5 ++- 6 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 CONTRIBUTING.md rename cmd/{ => aminoscan}/aminoscan.go (95%) rename cmd/{ => aminoscan}/colors.go (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62656b2b..8a554316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.14.1 (November 6, 2018) + +IMPROVEMENTS: + - go-amino compiles again on 32-bit platforms ([#242]) + +[#242]: https://github.com/tendermint/go-amino/pull/242 + ## 0.14.0 (October 26, 2018) BREAKING CHANGE: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..871ce04d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,63 @@ +# Contributing + +Thank you for considering making contributions to go-amino! This repository follows the [contribution guidelines] of +tendermint and the corresponding [coding repo]. Please take a look if you are not already familiar with those. + +Besides what you can find in aforementioned resources, there are a few things to consider specific to go-amino. +They are outlined below. + +## Compatibility + +### Protobuf + +Amino aims to be and stay [protobuf] compatible. Please, ensure that any change you add retains protobuf compatibility. +Basic compatibility is ensured by tests. To not introduce a protobuf dependency, these tests are not run with every test +run, though. You need to turn on a [build flag] to build and run those tests. + +### Tendermint + +Please ensure that tendermint still passes all tests when run with your changes. You can do so by cloning [tendermint]. +Then update the dependency to your commit (or release) in the corresponding [Gopkg.toml] and run `dep ensure -v` to get +tendermint build with your amino version. Finally, run `make test` (all in the tendermint project directory). + + +## Fuzzers + +Amino is fuzzed using several fuzzers. At least run [gofuzz] by running the command: +``` +make test +``` +This is what circle-ci will also run for you. + +Ideally, run the more in-depth [go-fuzzer], too. They are currently not run by circel-ci and we need to run it manually +for any substantial change. +If go-fuzzer isn't installed on your system, make sure to run: +``` +go get -u github.com/dvyukov/go-fuzz/go-fuzz-build github.com/dvyukov/go-fuzz/go-fuzz +``` + +The fuzzers are run by: +``` +make gofuzz_json +``` +and +``` +make gofuzz_binary +``` +respectively. Both fuzzers will run in an endless loop and you have to quit them manually. They will output +any problems (crashers) on the commandline. You'll find details of those crashers in the project directories +`tests/fuzz/binary/crashers` and `tests/fuzz/json/crashers` respectively. + +If you find a crasher related to your changes please fix it, or file an issue containing the crasher information. + + +[contribution guidelines]: https://github.com/tendermint/tendermint/blob/master/CONTRIBUTING.md +[coding repo]: https://github.com/tendermint/coding +[gofuzz]: https://github.com/google/gofuzz +[go-fuzzer]: https://github.com/dvyukov/go-fuzz +[protobuf]: https://developers.google.com/protocol-buffers/ +[build flag]: https://github.com/tendermint/go-amino/blob/faa6e731944e2b7b6a46ad202902851e8ce85bee/tests/proto3/proto3_compat_test.go#L1 +[tendermint]: https://github.com/tendermint/tendermint/ +[Gopkg.toml]: https://github.com/tendermint/tendermint/blob/master/Gopkg.toml + + diff --git a/cmd/aminoscan.go b/cmd/aminoscan/aminoscan.go similarity index 95% rename from cmd/aminoscan.go rename to cmd/aminoscan/aminoscan.go index 1990691d..74c51897 100644 --- a/cmd/aminoscan.go +++ b/cmd/aminoscan/aminoscan.go @@ -20,8 +20,10 @@ func main() { // Parse flags... var colorize bool + var concreteName string flgs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) flgs.BoolVar(&colorize, "color", false, "Just print the colored bytes and exit.") + flgs.StringVar(&concreteName, "concrete-name", "", "Just print the concrete bytes for a concrete name and exit.") err := flgs.Parse(os.Args[1:]) if err == flag.ErrHelp { fmt.Println(`Usage: aminoscan or --help @@ -48,6 +50,13 @@ func main() { return } + // If we just want to print the concrete bytes... + if concreteName != "" { + db, pb := amino.NameToDisfix(concreteName) + fmt.Printf("Disamb bytes: %X\nPrefix bytes: %X\n", db, pb) + return + } + // Parse struct Amino bytes. bz := hexDecode(os.Args[1]) // Read input hex bytes. fmt.Println(Yellow("## Root Struct (assumed)")) diff --git a/cmd/colors.go b/cmd/aminoscan/colors.go similarity index 100% rename from cmd/colors.go rename to cmd/aminoscan/colors.go diff --git a/encoder.go b/encoder.go index be8267d1..644d706c 100644 --- a/encoder.go +++ b/encoder.go @@ -117,9 +117,9 @@ func EncodeFloat64(w io.Writer, f float64) (err error) { const ( // seconds of 01-01-0001 - minSeconds = -62135596800 + minSeconds int64 = -62135596800 // seconds of 10000-01-01 - maxSeconds = 253402300800 + maxSeconds int64 = 253402300800 // nanos have to be in interval: [0, 999999999] maxNanos = 999999999 @@ -137,9 +137,7 @@ func (e InvalidTimeErr) Error() string { // Milliseconds are used to ease compatibility with Javascript, // which does not support finer resolution. func EncodeTime(w io.Writer, t time.Time) (err error) { - var s = t.Unix() - var ns = int32(t.Nanosecond()) // this int64 -> int32 is safe. - + s := t.Unix() // TODO: We are hand-encoding a struct until MarshalAmino/UnmarshalAmino is supported. // skip if default/zero value: if s != 0 { @@ -156,9 +154,10 @@ func EncodeTime(w io.Writer, t time.Time) (err error) { return } } + ns := int32(t.Nanosecond()) // this int64 -> int32 cast is safe (nanos are in [0, 999999999]) // skip if default/zero value: if ns != 0 { - // do not encode if not in interval [0, 999999999] + // do not encode if nanos exceed allowed interval if ns < 0 || ns > maxNanos { // we could as well panic here: // time.Time.Nanosecond() guarantees nanos to be in [0, 999,999,999] diff --git a/tests/fuzz/binary/init-corpus/main.go b/tests/fuzz/binary/init-corpus/main.go index 32d63b8c..95dc4d29 100644 --- a/tests/fuzz/binary/init-corpus/main.go +++ b/tests/fuzz/binary/init-corpus/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "log" + "math" "os" "path/filepath" "time" @@ -48,7 +49,7 @@ func main() { Int32Ar: [4]int32{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, 0x77777777}, Int64Ar: [4]int64{0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x80808000FFFFF}, VarintAr: [4]int64{0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x80808000FFFFF}, - IntAr: [4]int{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, 0x80808000}, + IntAr: [4]int{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, math.MaxInt32}, ByteAr: [4]byte{0xDE, 0xAD, 0xBE, 0xEF}, Uint8Ar: [4]uint8{0xFF, 0xFF, 0x00, 0x88}, Uint16Ar: [4]uint16{0xFFFF, 0xFFFF, 0xFF00, 0x8800}, @@ -66,7 +67,7 @@ func main() { Int32Sl: []int32{0x6FFFFFFF, 0x5FFFFFFF, 0x7FFFFFFF, 0x7F000000}, Int64Sl: []int64{0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x80808000FFFFF}, VarintSl: []int64{0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x80808000FFFFF}, - IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, 0x80808000, 0x5FFFFFFF}, + IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, math.MaxInt32, 0x5FFFFFFF}, ByteSl: []byte{0xAD, 0xBE, 0xDE, 0xEF}, Uint8Sl: []uint8{0xFF, 0x00, 0x88, 0xFF}, Uint16Sl: []uint16{0xFFFF, 0xFFFF, 0xFF00, 0x8800},