fix(math): preventative ciel call (#18519)
This commit is contained in:
parent
e7b1d10998
commit
bed952022b
@ -40,6 +40,10 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j
|
||||
|
||||
* [#18421](https://github.com/cosmos/cosmos-sdk/pull/18421) Add mutative api for `LegacyDec.BigInt()`.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [#18519](https://github.com/cosmos/cosmos-sdk/pull/18519) Prevent Overflow in `Dec.Ceil()`.
|
||||
|
||||
## [math/v1.2.0](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.2.0) - 2023-11-07
|
||||
|
||||
### Features
|
||||
|
||||
@ -742,6 +742,10 @@ func (d LegacyDec) Ceil() LegacyDec {
|
||||
return LegacyNewDecFromBigInt(quo)
|
||||
}
|
||||
|
||||
if d.i.BitLen() >= maxDecBitLen {
|
||||
panic("Int overflow")
|
||||
}
|
||||
|
||||
return LegacyNewDecFromBigInt(quo.Add(quo, oneInt))
|
||||
}
|
||||
|
||||
|
||||
@ -408,6 +408,14 @@ func (s *decimalTestSuite) TestDecCeil() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *decimalTestSuite) TestCeilOverflow() {
|
||||
d, err := math.LegacyNewDecFromStr("66749594872528440074844428317798503581334516323645399060845050244444366430645.000000000000000001")
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(d.BigInt().BitLen() <= 315, "d is too large")
|
||||
// this call panics because the value is too large
|
||||
s.Require().Panics(func() { d.Ceil() }, "Ceil should panic on overflow")
|
||||
}
|
||||
|
||||
func (s *decimalTestSuite) TestPower() {
|
||||
testCases := []struct {
|
||||
input math.LegacyDec
|
||||
|
||||
Loading…
Reference in New Issue
Block a user