Skip to content

Commit 07ee9e6

Browse files
committed
[release-branch.go1.16] math/big: prevent overflow in (*Rat).SetString
Credit to rsc@ for the original patch. Thanks to the OSS-Fuzz project for discovering this issue and to Emmanuel Odeke (@odeke_et) for reporting it. Updates #50699 Fixes #50700 Fixes CVE-2022-23772 Change-Id: I590395a3d55689625390cf1e58f5f40623b26ee5 Reviewed-on: https://go-review.googlesource.com/c/go/+/379537 Trust: Katie Hockman <[email protected]> Run-TryBot: Katie Hockman <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Julie Qiu <[email protected]> (cherry picked from commit ad345c2) Reviewed-on: https://go-review.googlesource.com/c/go/+/381337
1 parent 6cbcf58 commit 07ee9e6

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/math/big/ratconv.go

+5
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ func (z *Rat) SetString(s string) (*Rat, bool) {
169169
n := exp5
170170
if n < 0 {
171171
n = -n
172+
if n < 0 {
173+
// This can occur if -n overflows. -(-1 << 63) would become
174+
// -1 << 63, which is still negative.
175+
return nil, false
176+
}
172177
}
173178
if n > 1e6 {
174179
return nil, false // avoid excessively large exponents

src/math/big/ratconv_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ var setStringTests = []StringTest{
104104
{in: "4/3/"},
105105
{in: "4/3."},
106106
{in: "4/"},
107+
{in: "13e-9223372036854775808"}, // CVE-2022-23772
107108

108109
// valid
109110
{"0", "0", true},

0 commit comments

Comments
 (0)