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
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.MakeFromLiteralhanging. The reason for this is that a 0 mantissa is special-cased duringbig.Floatparsing, but not duringbig.Ratparsing. This means that a value like0e9999999999will parse successfully inbig.Float.SetString, but will hang inbig.Rat.SetString. This discrepancy becomes an issue inmakeFloatFromLiteral, where thebig.Floatwill report an exponent of0, sobig.Rat.SetStringwill be used and will subsequently hang.The solution to this problem is to special-case a zero mantissa during
big.Ratparsing as well, so that neitherbig.Ratnorbig.Floatwill hang when parsing a value with a0mantissa 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