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

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


Copy link

@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?


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, I ran the code in or inlined below

package main

import "math/big"

func main() {
	r := new(big.Rat)

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.shl({0xc000136008, 0x0, 0x0}, {0xc000136008, 0xc000140000, 0x0}, 0x113b270)
	/Users/emmanuelodeke/go/src/ +0x213
math/big.(*Rat).SetString(0xc00012bf30, {0x10b527e, 0xc0000001a0})
	/Users/emmanuelodeke/go/src/ +0x756
	/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
Copy link

@gopherbot gopherbot commented May 2, 2021

Change 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
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants