Skip to content

Commit

Permalink
x/ibc: fix int overflow (#6171)
Browse files Browse the repository at this point in the history
x/ibc/07-tendermint/types/test_utils.go: Calculate and use
machine-dependent maxInt instead of causing int overflow by
passing math.MaxInt64.

Closes: #6130
  • Loading branch information
Alessio Treglia committed May 8, 2020
1 parent fe9fe87 commit c8c4778
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions x/ibc/07-tendermint/types/test_utils.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package types

import (
"math"
"time"

"github.com/tendermint/tendermint/crypto/tmhash"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version"
)

const maxInt = int(^uint(0) >> 1)

// Copied unimported test functions from tmtypes to use them here
func MakeBlockID(hash []byte, partSetSize int, partSetHash []byte) tmtypes.BlockID {
return tmtypes.BlockID{
Expand All @@ -28,7 +29,7 @@ func CreateTestHeader(chainID string, height int64, timestamp time.Time, valSet
ChainID: chainID,
Height: height,
Time: timestamp,
LastBlockID: MakeBlockID(make([]byte, tmhash.Size), math.MaxInt64, make([]byte, tmhash.Size)),
LastBlockID: MakeBlockID(make([]byte, tmhash.Size), maxInt, make([]byte, tmhash.Size)),
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
DataHash: tmhash.Sum([]byte("data_hash")),
ValidatorsHash: vsetHash,
Expand Down

0 comments on commit c8c4778

Please sign in to comment.