@@ -1959,20 +1959,28 @@ and classes for traversing abstract syntax trees:
19591959
19601960.. function :: literal_eval(node_or_string)
19611961
1962- Safely evaluate an expression node or a string containing a Python literal or
1962+ Evaluate an expression node or a string containing only a Python literal or
19631963 container display. The string or node provided may only consist of the
19641964 following Python literal structures: strings, bytes, numbers, tuples, lists,
19651965 dicts, sets, booleans, ``None `` and ``Ellipsis ``.
19661966
1967- This can be used for safely evaluating strings containing Python values from
1968- untrusted sources without the need to parse the values oneself. It is not
1969- capable of evaluating arbitrarily complex expressions, for example involving
1970- operators or indexing.
1967+ This can be used for evaluating strings containing Python values without the
1968+ need to parse the values oneself. It is not capable of evaluating
1969+ arbitrarily complex expressions, for example involving operators or
1970+ indexing.
1971+
1972+ This function had been documented as "safe" in the past without defining
1973+ what that meant. That was misleading. This is specifically designed not to
1974+ execute Python code, unlike the more general :func: `eval `. There is no
1975+ namespace, no name lookups, or ability to call out. But it is not free from
1976+ attack: A relatively small input can lead to memory exhaustion or to C stack
1977+ exhaustion, crashing the process. There is also the possibility for
1978+ excessive CPU consumption denial of service on some inputs. Calling it on
1979+ untrusted data is thus not recommended.
19711980
19721981 .. warning ::
1973- It is possible to crash the Python interpreter with a
1974- sufficiently large/complex string due to stack depth limitations
1975- in Python's AST compiler.
1982+ It is possible to crash the Python interpreter due to stack depth
1983+ limitations in Python's AST compiler.
19761984
19771985 It can raise :exc: `ValueError `, :exc: `TypeError `, :exc: `SyntaxError `,
19781986 :exc: `MemoryError ` and :exc: `RecursionError ` depending on the malformed
0 commit comments