fix: nil pointer panic on `NewIntFromBigInt` (backport #9627) (#10845)

* types: fix nil pointer panic on `NewIntFromBigInt` (#9627)

(cherry picked from commit 7f9037490b)

# Conflicts:
#	CHANGELOG.md

* fix conflicts

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
This commit is contained in:
mergify[bot] 2021-12-29 21:21:31 +01:00 committed by GitHub
parent 51f7d31de5
commit f67928a86d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* (types) [\#9627](https://github.com/cosmos/cosmos-sdk/pull/9627) Fix nil pointer panic on `NewBigIntFromInt`.
* [#10725](https://github.com/cosmos/cosmos-sdk/pull/10725) populate `ctx.ConsensusParams` for begin/end blockers.
## [v0.44.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.5) - 2021-12-02

View File

@ -101,8 +101,13 @@ func NewIntFromUint64(n uint64) Int {
return Int{b}
}
// NewIntFromBigInt constructs Int from big.Int
// NewIntFromBigInt constructs Int from big.Int. If the provided big.Int is nil,
// it returns an empty instance. This function panics if the bit length is > 256.
func NewIntFromBigInt(i *big.Int) Int {
if i == nil {
return Int{}
}
if i.BitLen() > maxBitLen {
panic("NewIntFromBigInt() out of bound")
}

View File

@ -91,6 +91,9 @@ func (s *intTestSuite) TestIntPanic() {
s.Require().Panics(func() { intmax.Add(sdk.OneInt()) })
s.Require().Panics(func() { intmin.Sub(sdk.OneInt()) })
s.Require().NotPanics(func() { sdk.NewIntFromBigInt(nil) })
s.Require().True(sdk.NewIntFromBigInt(nil).IsNil())
// Division-by-zero check
s.Require().Panics(func() { i1.Quo(sdk.NewInt(0)) })