Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
casts.go: Added extra checks in builtinToNumber to reject NaN, Infini…
Browse files Browse the repository at this point in the history
…ty, and Inf.
sikehish committed Dec 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 976e2d4 commit 150394b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion topdown/casts.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,11 @@ func builtinToNumber(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term
case ast.Number:
return iter(ast.NewTerm(a))
case ast.String:
_, err := strconv.ParseFloat(string(a), 64)
strValue := string(a)
if strValue == "Inf" || strValue == "Infinity" || strValue == "NaN" {
return builtins.NewOperandTypeErr(1, operands[0].Value, "valid number string")
}
_, err := strconv.ParseFloat(strValue, 64)
if err != nil {
return err
}

0 comments on commit 150394b

Please sign in to comment.