Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions asteval/astutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def safe_pow(base, exp):

def safe_mult(arg1, arg2):
"""safe version of multiply"""
if isinstance(arg1, int) and isinstance(arg2, str):
arg1, arg2 = arg2, arg1
if isinstance(arg1, str) and isinstance(arg2, int) and len(arg1) * arg2 > MAX_STR_LEN:
raise RuntimeError(f"String length exceeded, max string length is {MAX_STR_LEN}")
return arg1 * arg2
Expand Down
2 changes: 2 additions & 0 deletions tests/test_asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,8 @@ def test_safe_funcs(nested):
check_error(interp, 'RuntimeError')
interp("'*'*(2<<17) + '*'")
check_error(interp, 'RuntimeError')
interp("(1+2<<17)*'*'")
check_error(interp, 'RuntimeError')
interp("1.01**10000")
check_error(interp, None)
interp("1.01**10001")
Expand Down