From 2757cf30f714d3e8bca9f0b165a47a4739827f67 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Mon, 5 Nov 2018 16:05:55 +0100 Subject: [PATCH 1/4] fix int overflows that happen on 32bit systems - explicitly type constant in time encoding - use math.MaxInt32 in int tests to seed the fuzzer --- encoder.go | 11 +++++------ tests/fuzz/binary/init-corpus/main.go | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/encoder.go b/encoder.go index be8267d1..033ad032 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}, From b65390867995ede4b5cd2812ab29f47f7d3c7a34 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Tue, 6 Nov 2018 13:07:28 +0100 Subject: [PATCH 2/4] update changelog for release --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) 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: From c3c05e6e84d0cc366f8ca53e4a94a2c1fe113a6b Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 6 Nov 2018 17:15:13 +0100 Subject: [PATCH 3/4] apply @melekes suggestions Co-Authored-By: Liamsi --- encoder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encoder.go b/encoder.go index 033ad032..2b7a9222 100644 --- a/encoder.go +++ b/encoder.go @@ -117,7 +117,7 @@ func EncodeFloat64(w io.Writer, f float64) (err error) { const ( // seconds of 01-01-0001 - minSeconds = int64(-62135596800) + minSeconds int64 = -62135596800 // seconds of 10000-01-01 maxSeconds = int64(253402300800) From bad74bd85d6761098ee51753970821777e0f16af Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 6 Nov 2018 17:15:33 +0100 Subject: [PATCH 4/4] apply @melekes suggestions Co-Authored-By: Liamsi --- encoder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encoder.go b/encoder.go index 2b7a9222..644d706c 100644 --- a/encoder.go +++ b/encoder.go @@ -119,7 +119,7 @@ const ( // seconds of 01-01-0001 minSeconds int64 = -62135596800 // seconds of 10000-01-01 - maxSeconds = int64(253402300800) + maxSeconds int64 = 253402300800 // nanos have to be in interval: [0, 999999999] maxNanos = 999999999