jackc / pgtype

MIT License
300 stars 111 forks source link

Unsafe type float64 conversion to float32 in AssignTo #172

Open ttrolololll opened 2 years ago

ttrolololll commented 2 years ago

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?

jackc commented 2 years ago

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.