Repository navigation
SympyFunction.to_sympy: an argument SymPy rejects leaves it unevaluated - #2043
Merged
Merged
Conversation
SympyFunction.to_sympy caught only TypeError from the SymPy call. SymPy also answers a meaningless argument with AttributeError or ValueError, e.g. asin(true): 'BooleanTrue' object has no attribute 'as_coefficient'. These escaped as Python exceptions, so Sin[True], Log[True], ArcTan[False], Erf[True], Conjugate[True], EuclideanDistance[True, 2] and the like crashed the session. In our fuzzing this affected 46 builtins. Such an expression now has no SymPy form and stays unevaluated, as for a TypeError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rocky
reviewed
Oct 18, 2026
| ("N[Sin[1], 40]", None, "0.8414709848078965066525023216302989996226", None), | ||
| ("Tan[0.5 Pi]", None, "1.63312×10^16", None), | ||
| # Arguments SymPy rejects leave the expression unevaluated. | ||
| ("Sin[True]", [], "Sin[True]", None), |
Member
There was a problem hiding this comment.
Please enhance the failure messages.
Collaborator
Author
There was a problem hiding this comment.
Done in dbd9ca4: each new case now says what it checks and why (SymPy rejects the Boolean argument, so the expression stays unevaluated).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
LGTM |
Member
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SympyFunction.to_sympy caught only TypeError from the SymPy call. SymPy
also answers a meaningless argument with AttributeError or ValueError,
e.g. asin(true): 'BooleanTrue' object has no attribute 'as_coefficient'.
These escaped as Python exceptions, so Sin[True], Log[True], ArcTan[False],
Erf[True], Conjugate[True], EuclideanDistance[True, 2] and the like
crashed the session. In our fuzzing this affected 46 builtins.
Such an expression now has no SymPy form and stays unevaluated, as for
a TypeError.
To reproduce on master:
Tests: new cases in
test/builtin/numbers/test_trig.py(test_trig). They fail on current master and pass with this change.The full pytest suite and the doctests pass with this change (run together with the other fixes from the same audit; the only pytest failures, in
test_main.pyandtest_returncode.py, are the same as on master and come from themathicsscript not being on PATH in our environment).Found in a correctness audit of Mathics3 (differential checks against SymPy/mpmath/exact computation, and calls of every builtin with edge-case arguments).
🤖 Generated with Claude Code