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

2.7 core crashes with generator.gi_frame.f_restricted #67040

Closed
doko42 opened this issue Nov 12, 2014 · 6 comments
Closed

2.7 core crashes with generator.gi_frame.f_restricted #67040

doko42 opened this issue Nov 12, 2014 · 6 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@doko42
Copy link
Member

doko42 commented Nov 12, 2014

BPO 22851
Nosy @terryjreedy, @doko42, @vstinner, @serhiy-storchaka, @eryksun, @ZackerySpytz
PRs
  • [2.7] bpo-22851: Fix a segfault when accessing generator.gi_frame.f_restricted #9348
  • 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-10-13.09:28:43.745>
    created_at = <Date 2014-11-12.10:20:31.876>
    labels = ['interpreter-core']
    title = '2.7 core crashes with generator.gi_frame.f_restricted'
    updated_at = <Date 2018-10-13.09:28:43.744>
    user = 'https://github.com/doko42'

    bugs.python.org fields:

    activity = <Date 2018-10-13.09:28:43.744>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-13.09:28:43.745>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2014-11-12.10:20:31.876>
    creator = 'doko'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 22851
    keywords = ['patch']
    message_count = 6.0
    messages = ['231069', '231072', '231075', '231186', '231193', '327643']
    nosy_count = 7.0
    nosy_names = ['terry.reedy', 'doko', 'vstinner', 'Arfrever', 'serhiy.storchaka', 'eryksun', 'ZackerySpytz']
    pr_nums = ['9348']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue22851'
    versions = ['Python 2.7']

    @doko42
    Copy link
    Member Author

    doko42 commented Nov 12, 2014

    seen with the current 2.7 branch:

    $ cat > x.py
    def foo(): yield
    gen = foo()
    print gen.gi_frame.f_restricted
    for i in gen: pass
    print gen.gi_frame
    gen = foo()
    print gen.next()
    print gen.gi_frame.f_restricted
    
    $ python x.py 
    False
    None
    None
    Segmentation fault

    Program received signal SIGSEGV, Segmentation fault.
    0x0000000000462b44 in frame_getrestricted (
    f=Frame 0x7ffff7f58410, for file x.py, line 1, in foo (), closure=0x0)
    at ../Objects/frameobject.c:383
    383 ../Objects/frameobject.c: No such file or directory.
    (gdb) bt
    #0 0x0000000000462b44 in frame_getrestricted (
    f=Frame 0x7ffff7f58410, for file x.py, line 1, in foo (), closure=0x0)
    at ../Objects/frameobject.c:383

    @doko42 doko42 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 12, 2014
    @eryksun
    Copy link
    Contributor

    eryksun commented Nov 12, 2014

    This is related to the fix for bpo-14432. gen_send_ex sets f->f_tstate to NULL, so PyFrame_IsRestricted segfaults:

        #define PyFrame_IsRestricted(f) \
            ((f)->f_builtins != (f)->f_tstate->interp->builtins)

    @vstinner
    Copy link
    Member

    Related change:

    New changeset aa324af42c0e by Victor Stinner in branch '2.7':
    Issue bpo-14432: Generator now clears the borrowed reference to the thread state
    http://hg.python.org/cpython/rev/aa324af42c0e

    @terryjreedy
    Copy link
    Member

    This appears to be 2.7 only as 3.4.2 stops on the first print with AttributeError: 'frame' object has no attribute 'f_restricted', which is not a crash.

    @terryjreedy terryjreedy changed the title core crashes 2.7 core crashes with generator.gi_frame.f_restricted Nov 14, 2014
    @eryksun
    Copy link
    Contributor

    eryksun commented Nov 14, 2014

    The fix for bpo-14432 was applied to 3.3, but I'm pretty sure 2.x PyFrame_IsRestricted is the only problem. Nothing else should see f_tstate when it's NULL. Also, f_tstate was dropped from PyFrameObject in 3.4.

    @serhiy-storchaka
    Copy link
    Member

    New changeset 68ddb59 by Serhiy Storchaka (Zackery Spytz) in branch '2.7':
    [2.7] bpo-22851: Fix a segfault when accessing generator.gi_frame.f_restricted. (GH-9348)
    68ddb59

    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants