Files
magpie/internal/provider/ruleparse_tokens_test.go
T
kevin 6d5893d400 fix(rules): reject nan/inf and overflowing token lengths (#877)
* fix(rules): reject nan/inf and overflowing token lengths

ParseTokens used ParseFloat and cast straight to int. Values like
"nan", "inf" and "1e20" therefore became a huge negative (or other
nonsensical) token threshold instead of an error.

* fix(rules): reject tokens at the float64 MaxInt boundary

float64(MaxInt) rounds to 2^63, so n > float64(MaxInt) let the
boundary through and int(2^63) becomes MinInt on amd64.
2026-10-05 16:31:07 +08:00

16 lines
386 B
Go

package provider
import "testing"
func TestParseTokensRejectsNonFinite(t *testing.T) {
for _, in := range []string{
"nan", "NaN", "inf", "+inf", "1e20", "1e308", "1e20k",
"9223372036854775808", "9223372036854775k",
"9223372036854775807", // float64 rounds this to 2^63 on amd64
} {
if n, err := ParseTokens(in); err == nil {
t.Errorf("%q accepted as %d", in, n)
}
}
}