pgtype icon indicating copy to clipboard operation
pgtype copied to clipboard

Unsafe type float64 conversion to float32 in AssignTo

Open ttrolololll opened this issue 3 years ago • 1 comments
trafficstars

Referring to here: https://github.com/jackc/pgtype/blob/12c49ee213fabc092f24b92db6874ed0d319d7b3/ext/shopspring-numeric/decimal.go#L127

case *float32:
    f, _ := src.Decimal.Float64()
    *v = float32(f)

The value f should perhaps be checked for overflow against float32, and return an overflow error when it occurs?

ttrolololll avatar Jun 29 '22 03:06 ttrolololll

Maybe... 🤷

shopspring decimal internally uses https://pkg.go.dev/math/big#Rat.Float64 can already overflow the float64 to +Inf. The float64 to float32 does the same thing.

jackc avatar Jul 01 '22 02:07 jackc