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

Weakref proxy crashes on null tp_iternext slot. #88883

Closed
xxm mannequin opened this issue Jul 23, 2021 · 6 comments
Closed

Weakref proxy crashes on null tp_iternext slot. #88883

xxm mannequin opened this issue Jul 23, 2021 · 6 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@xxm
Copy link
Mannequin

xxm mannequin commented Jul 23, 2021

BPO 44720
Nosy @ambv, @miss-islington, @sweeneyde
PRs
  • bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ #27316
  • [3.10] bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ (GH-27316) #27324
  • [3.9] bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ (GH-27316) #27325
  • Files
  • test.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 2021-07-24.09:46:50.166>
    created_at = <Date 2021-07-23.05:05:41.949>
    labels = ['interpreter-core', '3.8', '3.9', '3.10', '3.11', '3.7', 'type-crash']
    title = 'Weakref proxy crashes on null tp_iternext slot.'
    updated_at = <Date 2021-07-24.09:46:50.165>
    user = 'https://bugs.python.org/xxm'

    bugs.python.org fields:

    activity = <Date 2021-07-24.09:46:50.165>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-24.09:46:50.166>
    closer = 'lukasz.langa'
    components = ['Interpreter Core']
    creation = <Date 2021-07-23.05:05:41.949>
    creator = 'xxm'
    dependencies = []
    files = ['50171']
    hgrepos = []
    issue_num = 44720
    keywords = ['patch']
    message_count = 6.0
    messages = ['398029', '398114', '398127', '398131', '398132', '398133']
    nosy_count = 4.0
    nosy_names = ['lukasz.langa', 'miss-islington', 'Dennis Sweeney', 'xxm']
    pr_nums = ['27316', '27324', '27325']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue44720'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    @xxm
    Copy link
    Mannequin Author

    xxm mannequin commented Jul 23, 2021

    This piece of code is originally from https://github.com/python/cpython/tree/main/Lib/test/test_weakref.py. In function test_proxy_iter(), we change the original data dependency and then this generated test case (see the following "test.py") crashes Python.

    Crashing Python version: 3.6-master(3.11.0a0)

    test.py
    =========================

    import weakref
    
    
    def test_proxy_iter():
        obj = None
    
        class MyObj:
            def __iter__(a):
                nonlocal obj
                del obj
    -           return NotImplemented
    +           return p
        obj = MyObj()
    -   p = weakref.proxy(obj)
    +   p = weakref.proxy(TypeError)
    • 'blech' in p
      + 'blech' in obj
    test_proxy_iter()

    ===========================

    system: ubuntu 16.04
    crash: segmentation fault

    @xxm xxm mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 23, 2021
    @sweeneyde
    Copy link
    Member

    Here's a simpler reproducer:

            not_an_iterator = lambda: 0
    
            class A:
                def __iter__(self):
                    return weakref.proxy(not_an_iterator)
            a = A()
            list(a)

    I opened a PR.

    @sweeneyde sweeneyde changed the title Finding string in iteratively deleted object cause segfault Weakref proxy crashes on null tp_iternext slot. Jul 24, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 24, 2021

    New changeset 5370f0a by Dennis Sweeney in branch 'main':
    bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ (GH-27316)
    5370f0a

    @ambv
    Copy link
    Contributor

    ambv commented Jul 24, 2021

    New changeset 659030c by Miss Islington (bot) in branch '3.10':
    bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ (GH-27316) (GH-27324)
    659030c

    @ambv
    Copy link
    Contributor

    ambv commented Jul 24, 2021

    New changeset 0a08f22 by Miss Islington (bot) in branch '3.9':
    bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ (GH-27316) (bpo-27325)
    0a08f22

    @ambv
    Copy link
    Contributor

    ambv commented Jul 24, 2021

    Thanks for your quick pull request, Dennis! ✨ 🍰 ✨

    @ambv ambv closed this as completed Jul 24, 2021
    @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 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 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