Skip to content

Commit dc14acf

Browse files
authored
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
1 parent 6dcc6dd commit dc14acf

File tree

6 files changed

+87
-8
lines changed

6 files changed

+87
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.14.1 (November 6, 2018)
4+
5+
IMPROVEMENTS:
6+
- go-amino compiles again on 32-bit platforms ([#242])
7+
8+
[#242]: https://github.com/tendermint/go-amino/pull/242
9+
310
## 0.14.0 (October 26, 2018)
411

512
BREAKING CHANGE:

CONTRIBUTING.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Contributing
2+
3+
Thank you for considering making contributions to go-amino! This repository follows the [contribution guidelines] of
4+
tendermint and the corresponding [coding repo]. Please take a look if you are not already familiar with those.
5+
6+
Besides what you can find in aforementioned resources, there are a few things to consider specific to go-amino.
7+
They are outlined below.
8+
9+
## Compatibility
10+
11+
### Protobuf
12+
13+
Amino aims to be and stay [protobuf] compatible. Please, ensure that any change you add retains protobuf compatibility.
14+
Basic compatibility is ensured by tests. To not introduce a protobuf dependency, these tests are not run with every test
15+
run, though. You need to turn on a [build flag] to build and run those tests.
16+
17+
### Tendermint
18+
19+
Please ensure that tendermint still passes all tests when run with your changes. You can do so by cloning [tendermint].
20+
Then update the dependency to your commit (or release) in the corresponding [Gopkg.toml] and run `dep ensure -v` to get
21+
tendermint build with your amino version. Finally, run `make test` (all in the tendermint project directory).
22+
23+
24+
## Fuzzers
25+
26+
Amino is fuzzed using several fuzzers. At least run [gofuzz] by running the command:
27+
```
28+
make test
29+
```
30+
This is what circle-ci will also run for you.
31+
32+
Ideally, run the more in-depth [go-fuzzer], too. They are currently not run by circel-ci and we need to run it manually
33+
for any substantial change.
34+
If go-fuzzer isn't installed on your system, make sure to run:
35+
```
36+
go get -u github.com/dvyukov/go-fuzz/go-fuzz-build github.com/dvyukov/go-fuzz/go-fuzz
37+
```
38+
39+
The fuzzers are run by:
40+
```
41+
make gofuzz_json
42+
```
43+
and
44+
```
45+
make gofuzz_binary
46+
```
47+
respectively. Both fuzzers will run in an endless loop and you have to quit them manually. They will output
48+
any problems (crashers) on the commandline. You'll find details of those crashers in the project directories
49+
`tests/fuzz/binary/crashers` and `tests/fuzz/json/crashers` respectively.
50+
51+
If you find a crasher related to your changes please fix it, or file an issue containing the crasher information.
52+
53+
54+
[contribution guidelines]: https://github.com/tendermint/tendermint/blob/master/CONTRIBUTING.md
55+
[coding repo]: https://github.com/tendermint/coding
56+
[gofuzz]: https://github.com/google/gofuzz
57+
[go-fuzzer]: https://github.com/dvyukov/go-fuzz
58+
[protobuf]: https://developers.google.com/protocol-buffers/
59+
[build flag]: https://github.com/tendermint/go-amino/blob/faa6e731944e2b7b6a46ad202902851e8ce85bee/tests/proto3/proto3_compat_test.go#L1
60+
[tendermint]: https://github.com/tendermint/tendermint/
61+
[Gopkg.toml]: https://github.com/tendermint/tendermint/blob/master/Gopkg.toml
62+
63+

cmd/aminoscan.go renamed to cmd/aminoscan/aminoscan.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ func main() {
2020

2121
// Parse flags...
2222
var colorize bool
23+
var concreteName string
2324
flgs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
2425
flgs.BoolVar(&colorize, "color", false, "Just print the colored bytes and exit.")
26+
flgs.StringVar(&concreteName, "concrete-name", "", "Just print the concrete bytes for a concrete name and exit.")
2527
err := flgs.Parse(os.Args[1:])
2628
if err == flag.ErrHelp {
2729
fmt.Println(`Usage: aminoscan <STRUCT HEXBYTES> or --help
@@ -48,6 +50,13 @@ func main() {
4850
return
4951
}
5052

53+
// If we just want to print the concrete bytes...
54+
if concreteName != "" {
55+
db, pb := amino.NameToDisfix(concreteName)
56+
fmt.Printf("Disamb bytes: %X\nPrefix bytes: %X\n", db, pb)
57+
return
58+
}
59+
5160
// Parse struct Amino bytes.
5261
bz := hexDecode(os.Args[1]) // Read input hex bytes.
5362
fmt.Println(Yellow("## Root Struct (assumed)"))
File renamed without changes.

encoder.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ func EncodeFloat64(w io.Writer, f float64) (err error) {
117117

118118
const (
119119
// seconds of 01-01-0001
120-
minSeconds = -62135596800
120+
minSeconds int64 = -62135596800
121121
// seconds of 10000-01-01
122-
maxSeconds = 253402300800
122+
maxSeconds int64 = 253402300800
123123

124124
// nanos have to be in interval: [0, 999999999]
125125
maxNanos = 999999999
@@ -137,9 +137,7 @@ func (e InvalidTimeErr) Error() string {
137137
// Milliseconds are used to ease compatibility with Javascript,
138138
// which does not support finer resolution.
139139
func EncodeTime(w io.Writer, t time.Time) (err error) {
140-
var s = t.Unix()
141-
var ns = int32(t.Nanosecond()) // this int64 -> int32 is safe.
142-
140+
s := t.Unix()
143141
// TODO: We are hand-encoding a struct until MarshalAmino/UnmarshalAmino is supported.
144142
// skip if default/zero value:
145143
if s != 0 {
@@ -156,9 +154,10 @@ func EncodeTime(w io.Writer, t time.Time) (err error) {
156154
return
157155
}
158156
}
157+
ns := int32(t.Nanosecond()) // this int64 -> int32 cast is safe (nanos are in [0, 999999999])
159158
// skip if default/zero value:
160159
if ns != 0 {
161-
// do not encode if not in interval [0, 999999999]
160+
// do not encode if nanos exceed allowed interval
162161
if ns < 0 || ns > maxNanos {
163162
// we could as well panic here:
164163
// time.Time.Nanosecond() guarantees nanos to be in [0, 999,999,999]

tests/fuzz/binary/init-corpus/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"log"
7+
"math"
78
"os"
89
"path/filepath"
910
"time"
@@ -48,7 +49,7 @@ func main() {
4849
Int32Ar: [4]int32{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, 0x77777777},
4950
Int64Ar: [4]int64{0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x80808000FFFFF},
5051
VarintAr: [4]int64{0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x80808000FFFFF},
51-
IntAr: [4]int{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, 0x80808000},
52+
IntAr: [4]int{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, math.MaxInt32},
5253
ByteAr: [4]byte{0xDE, 0xAD, 0xBE, 0xEF},
5354
Uint8Ar: [4]uint8{0xFF, 0xFF, 0x00, 0x88},
5455
Uint16Ar: [4]uint16{0xFFFF, 0xFFFF, 0xFF00, 0x8800},
@@ -66,7 +67,7 @@ func main() {
6667
Int32Sl: []int32{0x6FFFFFFF, 0x5FFFFFFF, 0x7FFFFFFF, 0x7F000000},
6768
Int64Sl: []int64{0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x80808000FFFFF},
6869
VarintSl: []int64{0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x80808000FFFFF},
69-
IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, 0x80808000, 0x5FFFFFFF},
70+
IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, math.MaxInt32, 0x5FFFFFFF},
7071
ByteSl: []byte{0xAD, 0xBE, 0xDE, 0xEF},
7172
Uint8Sl: []uint8{0xFF, 0x00, 0x88, 0xFF},
7273
Uint16Sl: []uint16{0xFFFF, 0xFFFF, 0xFF00, 0x8800},

0 commit comments

Comments
 (0)