I was working on a library called rows[https://github.com/turicas/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/__init__.py). After some time testing, I've came up with this piece of code to reproduce it: ``` try: float('áxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') except: 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 https://bugs.python.org/issue34087 but I preferred to create a new one since I don't know if there are automated tests for this specific case.
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 namedtuple_bug.py [...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 namedtuple_bug.py [...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 namedtuple_bug.py [...compilation lines supressed...] Python 3.7.0+ On master branch (2c8ddcf4f14f3e4c87a6fe6678ab5ad09130c6ab) it also works: $ git checkout master && make clean && ./configure && make && ./python --version && ./python namedtuple_bug.py [...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.
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.
Yes, I think it was fixed in https://bugs.python.org/issue34087 (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).
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 and is not reproducible on latest master and 3.7 branch. Feel free to reopen this if needed. Thanks again!
History
Date
User
Action
Args
2022-04-11 14:59:05
admin
set
github: 78720
2018-09-24 15:50:48
xtreak
set
status: open -> closedresolution: out of datemessages: + stage: resolved