Skip to content

Commit

Permalink
fix bound
Browse files Browse the repository at this point in the history
  • Loading branch information
liamsi committed Sep 8, 2018
1 parent 3af4656 commit b1924f9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ func decodeSeconds(bz *[]byte) (int64, int, error) {
// if seconds where negative before casting them to uint64, we yield
// the original signed value:
res := int64(sec)
if res < minSeconds || res > maxSeconds {
return 0, n, InvalidTimeErr(fmt.Sprintf("seconds have to be > %d and <= %d, got: %d",
if res < minSeconds || res >= maxSeconds {
return 0, n, InvalidTimeErr(fmt.Sprintf("seconds have to be > %d and < %d, got: %d",
minSeconds, maxSeconds, res))
}
return res, n, err
Expand Down Expand Up @@ -271,7 +271,7 @@ func decodeNanos(bz *[]byte, n *int) (int32, error) {
return 0, err
}
// Validation check.
if nsec < 0 || 999999999 < nsec {
if nsec < 0 || maxNanos < nsec {
return 0, InvalidTimeErr(fmt.Sprintf("nanoseconds not in interval [0, 999999999] %v", nsec))
}
// this cast from uint64 to int32 is OK, due to above restriction:
Expand Down
4 changes: 2 additions & 2 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func EncodeTime(w io.Writer, t time.Time) (err error) {
// TODO: We are hand-encoding a struct until MarshalAmino/UnmarshalAmino is supported.
// skip if default/zero value:
if s != 0 {
if s < minSeconds || s > maxSeconds {
return InvalidTimeErr(fmt.Sprintf("seconds have to be > %d and <= %d, got: %d",
if s < minSeconds || s >= maxSeconds {
return InvalidTimeErr(fmt.Sprintf("seconds have to be > %d and < %d, got: %d",
minSeconds, maxSeconds, s))
}
err = encodeFieldNumberAndTyp3(w, 1, Typ3_Varint)
Expand Down
2 changes: 1 addition & 1 deletion time2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestMinMaxTimeEncode(t *testing.T) {
assert.Error(t, err)
assert.IsType(t, InvalidTimeErr("invalid time: seconds have to be > -62135596800 and <= 253402300800, got: -62135596801"), err)

tErrMaxSec := time.Unix(maxSeconds+1, 0)
tErrMaxSec := time.Unix(maxSeconds, 0)
_, err = cdc.MarshalBinaryBare(tErrMaxSec)
assert.Error(t, err)
assert.IsType(t, InvalidTimeErr("invalid time: seconds have to be > -62135596800 and <= 253402300800, got: -62135596801"), err)
Expand Down

0 comments on commit b1924f9

Please sign in to comment.