Title: namedtuple's exec() throws segmentation fault
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.7
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, turicas, xtreak
Priority: normal Keywords:

Created on 2018-08-29 04:20 by turicas, last changed 2018-09-24 15:50 by xtreak. This issue is now closed.

File name Uploaded Description Edit turicas, 2018-08-29 04:20
Messages (6)
msg324300 - (view) Author: Álvaro Justen (turicas) Date: 2018-08-29 04:20
I was working on a library called rows[] when a segmentation fault was thrown in the moment I've tried to read a CSV file. Since this part of the code is implemented completely in Python, I thought it could be a bug in Python itself.
Investigating the code I found it was faulting at exec()'s line inside namedtuple code (Lib/collections/ After some time testing, I've came up with this piece of code to reproduce it:

    from collections import namedtuple
    namedtuple('T', 'f')

The code works if I:
- Run passing `PYTHONMALLOC=debug`
- Place 'from collections import namedtuple' into the first line
- Remove any char from the string in the 'float(...)' line
- Remove the 'á' from the string in the 'float(...)' line

I've tested the code on Python 3.6.6, 3.7.0, 3.7-dev and 3.8-dev (versions installed using pyenv on a Debian GNU/Linux machine) and the problem happened only in 3.7.0.
This issue seems to be related to but I preferred to create a new one since I don't know if there are automated tests for this specific case.
msg324314 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-08-29 09:46
The works for me.  Can you try it on a fresh build or install of Python 3.7?
msg324325 - (view) Author: Álvaro Justen (turicas) Date: 2018-08-29 14:25
I've cloned the cpython git repository and made fresh builds here:

On v.3.6.6 (4cf1f54eb764f856fda5a394d8598c0c90d69d77) it works:

    $ git checkout v3.6.6 && ./configure && make && ./python --version && ./python
    [...compilation lines supressed...]
    Python 3.6.6

On the v.3.7.0 (1bf9cc509326bc42cd8cb1650eb9bf64550d817e) it segfaults:

    $ git checkout v3.7.0 && make clean && ./configure && make && ./python --version && ./python
    [...compilation lines supressed...]
    Python 3.7.0
    Segmentation fault

On the most recent 3.7 branch (65ef7425a32ee411d8047a4fad0fc6bb9ff733b1) it works:

    $ git checkout 3.7 && make clean && ./configure && make && ./python --version && ./python
    [...compilation lines supressed...]
    Python 3.7.0+

On master branch (2c8ddcf4f14f3e4c87a6fe6678ab5ad09130c6ab) it also works:

    $ git checkout master && make clean && ./configure && make && ./python --version && ./python
    [...compilation lines supressed...]
    Python 3.8.0a0

Note: I've tried to add a `print('works!')` at the end of the script, so we can see the result when it does not segfault, but adding this actually make it works on all versions; removing this line has the behaviour reported above.
msg324357 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-08-29 23:06
If this is only present in 3.7.0 and not in the current branches, it implies there was an exec() or ceval-loop bug in that release and it has been already fixed.

This bug report may be out-of-date.
msg324387 - (view) Author: Álvaro Justen (turicas) Date: 2018-08-30 15:44
Yes, I think it was fixed in (didn't see the commits), I just wanted to report it because I don't know if a test for this specific case is needed (the other bug is not related to namedtuples).
msg326256 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-24 15:50
Thanks Álvaro for the report and script. As part of triaging I am closing this as out of date since this bug seemed to have been fixed with issue34087 and is not reproducible on latest master and 3.7 branch. Feel free to reopen this if needed.

Thanks again!
Date User Action Args
2018-09-24 15:50:48xtreaksetstatus: open -> closed
resolution: out of date
messages: + msg326256

stage: resolved
2018-08-30 15:44:17turicassetmessages: + msg324387
2018-08-30 13:50:02xtreaksetnosy: + xtreak
2018-08-29 23:06:13rhettingersetmessages: + msg324357
2018-08-29 14:25:58turicassetmessages: + msg324325
2018-08-29 09:46:30rhettingersetnosy: + rhettinger
messages: + msg324314
2018-08-29 04:20:50turicascreate