]> Cypherpunks.ru repositories - gostls13.git/commit
math/big: special-case a 0 mantissa during Rat parsing
authorNathan VanBenschoten <nvanbenschoten@gmail.com>
Thu, 23 Jun 2016 23:46:13 +0000 (19:46 -0400)
committerRobert Griesemer <gri@golang.org>
Fri, 24 Jun 2016 20:51:06 +0000 (20:51 +0000)
commit5e43dc943a9265ec65690242eb8076727c18a958
tree7f7976518568b1ec43d0daffd48617ac48f750ab
parent797dc584577c66ee1e181a3f423133ee83647247
math/big: special-case a 0 mantissa during Rat parsing

Previously, a 0 mantissa was special-cased during big.Float
parsing, but not during big.Rat parsing. This meant that a value
like 0e9999999999 would parse successfully in big.Float.SetString,
but would hang in big.Rat.SetString. This discrepancy became an
issue in https://golang.org/src/go/constant/value.go?#L250,
where the big.Float would report an exponent of 0, so
big.Rat.SetString would be used and would subsequently hang.

A Go Playground example of this is https://play.golang.org/p/3fy28eUJuF

The solution 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 0 mantissa but a large exponent.

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

Fixes #16176

Change-Id: I775558a8682adbeba1cc9d20ba10f8ed26259c56
Reviewed-on: https://go-review.googlesource.com/24430
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/go/constant/value_test.go
src/math/big/ratconv.go
src/math/big/ratconv_test.go