<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><br><br><blockquote type="cite"><div><span>But the point is that the compiler is recursive, and processing nested constructs consumes the C stack. There are some guards against too deep recursion (2.7 has less guards and more vulnerable), but it is hard to prove that all vulnerabilities are fixed.</span><br><span></span><br><span>Your method (limiting the size of the input) helps against some attacks. Other methods -- restricting the set of characters and the number of parenthesis, braces and brackets.</span><br></div></blockquote><div><br></div><div>Hmm — I’d never really thought about it, bust presumably ast.literal_eval was designed for use in the compiler— or at least uses the compiler to do its real work.</div><div><br></div><div>So maybe what we really need is a literal-eval that is DESIGNED to be a safe Python literal parser.</div><div><br></div><div>Like a JSON parser but supporting the richer Python literal set.</div><div><br></div><div>-CHB</div><div><br></div><blockquote type="cite"><div><span></span></div></blockquote></body></html>