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

Segmentation fault with nonlocal and two underscores #70161

Closed
sirkonst mannequin opened this issue Dec 29, 2015 · 10 comments
Closed

Segmentation fault with nonlocal and two underscores #70161

sirkonst mannequin opened this issue Dec 29, 2015 · 10 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@sirkonst
Copy link
Mannequin

sirkonst mannequin commented Dec 29, 2015

BPO 25973
Nosy @brettcannon, @birkenfeld, @ncoghlan, @benjaminp, @serhiy-storchaka, @1st1, @ztane, @alessandrocucci
Files
  • test_issue25973.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 2015-12-29.16:09:27.022>
    created_at = <Date 2015-12-29.11:40:03.945>
    labels = ['interpreter-core', 'type-crash']
    title = 'Segmentation fault with nonlocal and two underscores'
    updated_at = <Date 2016-03-05.17:21:34.047>
    user = 'https://bugs.python.org/sirkonst'

    bugs.python.org fields:

    activity = <Date 2016-03-05.17:21:34.047>
    actor = 'ncoghlan'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-12-29.16:09:27.022>
    closer = 'python-dev'
    components = ['Interpreter Core']
    creation = <Date 2015-12-29.11:40:03.945>
    creator = 'sirkonst'
    dependencies = []
    files = ['41445']
    hgrepos = []
    issue_num = 25973
    keywords = []
    message_count = 10.0
    messages = ['257174', '257177', '257180', '257182', '257183', '257185', '257197', '261200', '261201', '261216']
    nosy_count = 10.0
    nosy_names = ['brett.cannon', 'georg.brandl', 'ncoghlan', 'benjamin.peterson', 'python-dev', 'serhiy.storchaka', 'yselivanov', 'ztane', 'acucci', 'sirkonst']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue25973'
    versions = ['Python 3.5', 'Python 3.6']

    @sirkonst
    Copy link
    Mannequin Author

    sirkonst mannequin commented Dec 29, 2015

    Code:
    # -------------------------------

    __obj = object()
    
    class Foo:
        def f1(self):
            nonlocal __obj
    
    f = Foo()
    f.f1()  # <-- segmentation fault
    #
    ```-------------------------------

    @sirkonst sirkonst mannequin added the type-crash A hard crash of the interpreter, possibly with a core dump label Dec 29, 2015
    @SilentGhost SilentGhost mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Dec 29, 2015
    @serhiy-storchaka
    Copy link
    Member

    I get a crash when just compile the example.

    @alessandrocucci
    Copy link
    Mannequin

    alessandrocucci mannequin commented Dec 29, 2015

    I don't think the problem is about the underscores, since this work...

    class Foo:
        def f1(self):
            __obj = object()
            def f2():
                nonlocal __obj
                __obj = []
            f2()
            return isinstance(__obj, list)
            
    f = Foo()
    print(f.f1())

    @sirkonst
    Copy link
    Mannequin Author

    sirkonst mannequin commented Dec 29, 2015

    The problem happens only when "nonlocal __something" in a class method. In your case f2() isn't class method.

    More interesting behavior with underscores - https://gist.github.com/sirkonst/6eff694c4546700417ea

    @alessandrocucci
    Copy link
    Mannequin

    alessandrocucci mannequin commented Dec 29, 2015

    quoting the docs:

    The statement [nonlocal] allows encapsulated code to rebind variables outside of the local scope BESIDES the global (module) scope.

    @sirkonst
    Copy link
    Mannequin Author

    sirkonst mannequin commented Dec 29, 2015

    Yes. Case:

    # -------------------

    class A:
        def f(self):
            nonlocal __x
    # 

    must raises SyntaxError like case:

    # -------------------

    class A:
        def f(self):
            nonlocal x

    > SyntaxError: no binding for nonlocal 'x' found
    # -------------------

    but doesn't crash with SegFault as it is now.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 29, 2015

    New changeset 4fa8c0c69ee9 by Benjamin Peterson in branch '3.5':
    make recording and reporting errors and nonlocal and global directives more robust (closes bpo-25973)
    https://hg.python.org/cpython/rev/4fa8c0c69ee9

    New changeset c64e68d703cf by Benjamin Peterson in branch 'default':
    merge 3.5 (bpo-25973)
    https://hg.python.org/cpython/rev/c64e68d703cf

    @python-dev python-dev mannequin closed this as completed Dec 29, 2015
    @ztane
    Copy link
    Mannequin

    ztane mannequin commented Mar 4, 2016

    So no fix for 3.4 for an obvious SIGSEGV?

        % python3  
        Python 3.4.3 (default, Mar 26 2015, 22:03:40) 
        [GCC 4.9.2] on linux
        Type "help", "copyright", "credits" or "license" for more information.
        >>> class A:
        ...     def f(self):
        ...         nonlocal __x
        ... 
        [4]    19173 segmentation fault (core dumped)  python3

    @serhiy-storchaka
    Copy link
    Member

    Only security fixes are accepted for 3.4.

    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Mar 5, 2016

    And as some additional background as to why segmentation faults provoked by Python code aren't currently considered a security bug: since CPython doesn't include a security sandbox, we're already relying entirely on the OS to provide process isolation.

    That OS level security boundary isn't affected by whether the code is running "normally", or in a modified state following a deliberately triggered segmentation fault.

    @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) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants