@@ -1991,20 +1991,28 @@ and classes for traversing abstract syntax trees:
19911991
19921992.. function :: literal_eval(node_or_string)
19931993
1994- Safely evaluate an expression node or a string containing a Python literal or
1994+ Evaluate an expression node or a string containing only a Python literal or
19951995 container display. The string or node provided may only consist of the
19961996 following Python literal structures: strings, bytes, numbers, tuples, lists,
19971997 dicts, sets, booleans, ``None `` and ``Ellipsis ``.
19981998
1999- This can be used for safely evaluating strings containing Python values from
2000- untrusted sources without the need to parse the values oneself. It is not
2001- capable of evaluating arbitrarily complex expressions, for example involving
2002- operators or indexing.
1999+ This can be used for evaluating strings containing Python values without the
2000+ need to parse the values oneself. It is not capable of evaluating
2001+ arbitrarily complex expressions, for example involving operators or
2002+ indexing.
2003+
2004+ This function had been documented as "safe" in the past without defining
2005+ what that meant. That was misleading. This is specifically designed not to
2006+ execute Python code, unlike the more general :func: `eval `. There is no
2007+ namespace, no name lookups, or ability to call out. But it is not free from
2008+ attack: A relatively small input can lead to memory exhaustion or to C stack
2009+ exhaustion, crashing the process. There is also the possibility for
2010+ excessive CPU consumption denial of service on some inputs. Calling it on
2011+ untrusted data is thus not recommended.
20032012
20042013 .. warning ::
2005- It is possible to crash the Python interpreter with a
2006- sufficiently large/complex string due to stack depth limitations
2007- in Python's AST compiler.
2014+ It is possible to crash the Python interpreter due to stack depth
2015+ limitations in Python's AST compiler.
20082016
20092017 It can raise :exc: `ValueError `, :exc: `TypeError `, :exc: `SyntaxError `,
20102018 :exc: `MemoryError ` and :exc: `RecursionError ` depending on the malformed
0 commit comments