golang/go

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

nvanbenschoten opened this issue · 1 comments

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

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