This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: crash in PyAST_Compile when running Python code
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: 12575 Superseder:
Assigned To: Nosy List: Albert.Zeyer, benjamin.peterson, daniel.urban, ezio.melotti, meador.inge, r.david.murray
Priority: normal Keywords: patch

Created on 2011-07-22 13:13 by Albert.Zeyer, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue12608.patch meador.inge, 2011-08-07 01:20 Patch against tip (3.3.0a0) review
Messages (8)
msg140873 - (view) Author: Albert Zeyer (Albert.Zeyer) * Date: 2011-07-22 13:13
Code:

```
import ast

globalsDict = {}

fAst = ast.FunctionDef(
	name="foo",
	args=ast.arguments(
		args=[], vararg=None, kwarg=None, defaults=[],
		kwonlyargs=[], kw_defaults=[]),
	body=[], decorator_list=[])

exprAst = ast.Interactive(body=[fAst])
ast.fix_missing_locations(exprAst)
compiled = compile(exprAst, "<foo>", "single")
eval(compiled, globalsDict, globalsDict)

print(globalsDict["foo"])
```

Also CPython 2.6, 2.7, 3.0 and PyPy 1.5 crashes on this.
msg140874 - (view) Author: Albert Zeyer (Albert.Zeyer) * Date: 2011-07-22 13:17
PyPy bug report: https://bugs.pypy.org/issue806
msg140875 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-07-22 13:24
So does default.
msg141733 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2011-08-07 01:20
Thanks for the test case Albert.  The attached patch adds a unit test based off of the given repro case and fixes the bug in the FunctionDef compiler.  The compiler was hitting a NULL pointer deref on FunctionDefs with empty list bodies.

Reproduced and fixed on tip.  Full test suite ran on Fedora 15; no regressions.
msg141848 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-08-10 01:14
Officially fixed by #12575.
msg141867 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2011-08-10 15:23
I have verified that the code checked in for issue12575 keep the test case from this issue from crashing the interpreter:

[meadori@motherbrain cpython]$ ./python test.py 
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    compiled = compile(exprAst, "<foo>", "single")
ValueError: empty body on FunctionDef

Do we have any intent on fixing this crasher for 3.2 and 2.7?
msg141869 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-08-10 15:30
2011/8/10 Meador Inge <report@bugs.python.org>:
>
> Meador Inge <meadori@gmail.com> added the comment:
>
> I have verified that the code checked in for issue12575 keep the test case from this issue from crashing the interpreter:
>
> [meadori@motherbrain cpython]$ ./python test.py
> Traceback (most recent call last):
>  File "test.py", line 14, in <module>
>    compiled = compile(exprAst, "<foo>", "single")
> ValueError: empty body on FunctionDef
>
> Do we have any intent on fixing this crasher for 3.2 and 2.7?

Probably not. Everything is rather broken before 3.3 now.
msg141882 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2011-08-10 19:59
OK, I am marking this as fixed then.  If someone decides to fix this in 3.2 or 3.7, then they can reopen the issue.
History
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56817
2011-08-10 19:59:05meador.ingesetstatus: open -> closed
resolution: fixed
messages: + msg141882

stage: patch review -> resolved
2011-08-10 15:30:06benjamin.petersonsetmessages: + msg141869
2011-08-10 15:23:10meador.ingesetmessages: + msg141867
2011-08-10 01:14:09benjamin.petersonsetmessages: + msg141848
2011-08-07 01:20:23meador.ingesetfiles: + issue12608.patch

nosy: + meador.inge
messages: + msg141733

keywords: + patch
stage: patch review
2011-07-23 12:05:40benjamin.petersonsetdependencies: + add a AST validator
2011-07-22 22:17:20ezio.melottisetnosy: + ezio.melotti
2011-07-22 17:32:46daniel.urbansetnosy: + daniel.urban
2011-07-22 13:24:30r.david.murraysetversions: + Python 2.7, Python 3.3
nosy: + r.david.murray, benjamin.peterson

messages: + msg140875

type: crash
2011-07-22 13:17:45Albert.Zeyersetmessages: + msg140874
2011-07-22 13:13:26Albert.Zeyercreate