Skip to content

Commit

Permalink
Release v0.14.1 (#244)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
liamsi committed Nov 11, 2018
1 parent 6dcc6dd commit dc14acf
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
63 changes: 63 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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


9 changes: 9 additions & 0 deletions cmd/aminoscan.go → cmd/aminoscan/aminoscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <STRUCT HEXBYTES> or --help
Expand All @@ -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)"))
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions tests/fuzz/binary/init-corpus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
"math"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down

0 comments on commit dc14acf

Please sign in to comment.