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

go/constant: MakeFromLiteral with 0 mantissa and large exponent hangs #16176

Closed
nvanbenschoten opened this issue Jun 24, 2016 · 1 comment
Closed
Milestone

Comments

@nvanbenschoten
Copy link
Contributor

See https://play.golang.org/p/lKi0ESs-FE for an example.

Passing a sting representation of a float value with a mantissa of zero and a huge exponent will result in constant.MakeFromLiteral hanging. The reason for this is that a 0 mantissa is special-cased during big.Float parsing, but not during big.Rat parsing. This means that a value like 0e9999999999 will parse successfully in big.Float.SetString, but will hang in big.Rat.SetString. This discrepancy becomes an issue in makeFloatFromLiteral, where the big.Float will report an exponent of 0, so big.Rat.SetString will be used and will subsequently hang.

The solution to this problem is to special-case a zero mantissa during big.Rat parsing as well, so that neither big.Rat nor big.Float will hang when parsing a value with a 0 mantissa but a large exponent. The fix is underway in https://go-review.googlesource.com/#/c/24430/.

This was discovered using go-fuzz on CockroachDB:
https://github.com/cockroachdb/go-fuzz/blob/master/examples/parser/main.go. @dvyukov

@griesemer griesemer added this to the Go1.7 milestone Jun 24, 2016
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/24430 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants