Skip to content

math/big: Float.GobDecode accepts an invalid form that panics in Int64, Float64, Int, and Rat #81695

Closed

Description

@nnnkkk7

Go version

go version go1.27.1 darwin/arm64 (also reproduced on tip at a532f49)

What did you do?

var f big.Float
fmt.Println(f.GobDecode([]byte{1, 6, 0, 0, 0, 64})) // form bits = 3
v, acc := f.Int64()
fmt.Println(v, acc)

The same bytes decode the same way through a gob.Decoder reading from a stream.

What did you see happen?

GobDecode returns nil, and Int64, Float64, Int and Rat panic with unreachable.
The decoded value is inconsistent in other ways too: String returns "0" while Sign returns 1.

What did you expect to see?

An error from GobDecode. The form field has three valid values (zero, finite, inf), and validate0, added for #57946, only checks the mantissa and precision of a finite value.
Int.GobDecode (#81490) and Rat.GobDecode (#81645) were fixed recently for the same kind of state that decodes without an error and panics later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions