Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: (*Rat).SetString with "1.770p02041010010011001001" crashes with "makeslice: len out of range" #45910

Open
odeke-em opened this issue May 2, 2021 · 1 comment
Assignees
Milestone

Comments

@odeke-em
Copy link
Member

@odeke-em odeke-em commented May 2, 2021

What version of Go are you using (go version)?

Go since Go1.13 when we added support for hexadecimal literals

Does this issue reproduce with the latest release?

Yes!

What operating system and processor architecture are you using (go env)?

Not applicable, present on all versions

What did you do?

Found by oss-fuzz https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33284, I ran the code in https://play.golang.org/p/pM4ROalIRvq or inlined below

package main

import "math/big"

func main() {
	r := new(big.Rat)
	r.SetString("1.770p02041010010011001001")
}

What did you expect to see?

No crash but the boolean value returned as false.

What did you see instead?

A crash resulting from us having passed in 31890781406421892 in make.

$ go run main.go 
panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
math/big.nat.make(...)
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/math/big/nat.go:69
math/big.nat.shl({0xc000136008, 0x0, 0x0}, {0xc000136008, 0xc000140000, 0x0}, 0x113b270)
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/math/big/nat.go:1010 +0x213
math/big.(*Rat).SetString(0xc00012bf30, {0x10b527e, 0xc0000001a0})
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/math/big/ratconv.go:188 +0x756
main.main()
	/Users/emmanuelodeke/Desktop/openSrc/bugs/golang/oss-fuzz/33284/main.go:7 +0x49
exit status 2

We should perhaps cap the value that we pass into make to avoid an OOM.
Kindly cc-ing @griesemer @findleyr @katiehockman @rolandshoemaker @FiloSottile

@griesemer griesemer self-assigned this May 2, 2021
@griesemer griesemer added this to the Go1.17 milestone May 2, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented May 2, 2021

Change https://golang.org/cl/316149 mentions this issue: math/big: check for excessive exponents in Rat.SetString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants