Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namedtuple's exec() throws segmentation fault #78720

Closed
turicas mannequin opened this issue Aug 29, 2018 · 6 comments
Closed

namedtuple's exec() throws segmentation fault #78720

turicas mannequin opened this issue Aug 29, 2018 · 6 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@turicas
Copy link
Mannequin

turicas mannequin commented Aug 29, 2018

BPO 34539
Nosy @rhettinger, @tirkarthi
Files
  • namedtuple_bug.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-09-24.15:50:48.324>
    created_at = <Date 2018-08-29.04:20:50.366>
    labels = ['3.7', 'library', 'type-crash']
    title = "namedtuple's exec() throws segmentation fault"
    updated_at = <Date 2018-09-24.15:50:48.322>
    user = 'https://bugs.python.org/turicas'

    bugs.python.org fields:

    activity = <Date 2018-09-24.15:50:48.322>
    actor = 'xtreak'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-09-24.15:50:48.324>
    closer = 'xtreak'
    components = ['Library (Lib)']
    creation = <Date 2018-08-29.04:20:50.366>
    creator = 'turicas'
    dependencies = []
    files = ['47772']
    hgrepos = []
    issue_num = 34539
    keywords = []
    message_count = 6.0
    messages = ['324300', '324314', '324325', '324357', '324387', '326256']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'turicas', 'xtreak']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue34539'
    versions = ['Python 3.7']

    @turicas
    Copy link
    Mannequin Author

    turicas mannequin commented Aug 29, 2018

    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.

    @turicas turicas mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Aug 29, 2018
    @rhettinger
    Copy link
    Contributor

    The works for me. Can you try it on a fresh build or install of Python 3.7?

    @turicas
    Copy link
    Mannequin Author

    turicas mannequin commented Aug 29, 2018

    I've cloned the cpython git repository and made fresh builds here:

    On v.3.6.6 (4cf1f54) 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 (1bf9cc5) 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 (65ef742) 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 (2c8ddcf) 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.

    @rhettinger
    Copy link
    Contributor

    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.

    @turicas
    Copy link
    Mannequin Author

    turicas mannequin commented Aug 30, 2018

    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).

    @tirkarthi
    Copy link
    Member

    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 bpo-34087 and is not reproducible on latest master and 3.7 branch. Feel free to reopen this if needed.

    Thanks again!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants