cockroachdb / apd

Arbitrary-precision decimals for Go
https://pkg.go.dev/github.com/cockroachdb/apd/v2
Apache License 2.0
664 stars 36 forks source link

panic with SetString(".-400000000000000000000000000000000000000") #120

Open josharian opened 2 years ago

josharian commented 2 years ago

This test panics:

func TestSetStringMalformed(t *testing.T) {
    c := &BaseContext
    d := new(Decimal)
    tests := []string{
        ".-4",
        ".-400000000000000000000000000000000000000",
    }
    for _, test := range tests {
        _, _, err := c.SetString(d, test)
        if err == nil {
            t.Errorf("expected error for SetString(%q)", test)
        }
    }
}

The panic is in the second test case. Also, I think ".-4" should yield an error (the first test case).


This was found (indirectly) by go-fuzz. Would there be interest in adding a fuzz function or three directly? (I don't have much time to dedicate to this, but I can at least give it a nudge, and/or continue my indirect fuzzing.)

nvanbenschoten commented 2 years ago

Would there be interest in adding a fuzz function or three directly?

Yes, any contribution (large or small) to improve the testing of this library would be appreciated.