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

class A(1, 2, 3, **d): pass gives bad bytecode #90319

Closed
zq1997 mannequin opened this issue Dec 23, 2021 · 5 comments
Closed

class A(1, 2, 3, **d): pass gives bad bytecode #90319

zq1997 mannequin opened this issue Dec 23, 2021 · 5 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@zq1997
Copy link
Mannequin

zq1997 mannequin commented Dec 23, 2021

BPO 46161
Nosy @markshannon, @sweeneyde, @zq1997
PRs
  • bpo-46161: fix the bug of starunpack_helper in compile.c #30235
  • 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 2022-02-07.11:34:54.795>
    created_at = <Date 2021-12-23.07:03:06.500>
    labels = ['3.10', '3.9', 'type-crash', '3.11']
    title = '`class A(1, 2, 3, **d): pass` gives bad bytecode'
    updated_at = <Date 2022-02-07.11:34:54.794>
    user = 'https://github.com/zq1997'

    bugs.python.org fields:

    activity = <Date 2022-02-07.11:34:54.794>
    actor = 'Mark.Shannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-07.11:34:54.795>
    closer = 'Mark.Shannon'
    components = []
    creation = <Date 2021-12-23.07:03:06.500>
    creator = 'zq1997'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46161
    keywords = []
    message_count = 5.0
    messages = ['409069', '409073', '409079', '410813', '412734']
    nosy_count = 3.0
    nosy_names = ['Mark.Shannon', 'Dennis Sweeney', 'zq1997']
    pr_nums = ['30235']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue46161'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @zq1997
    Copy link
    Mannequin Author

    zq1997 mannequin commented Dec 23, 2021

    Please refer to #30235

    @zq1997 zq1997 mannequin added build The build process and cross-build labels Dec 23, 2021
    @sweeneyde
    Copy link
    Member

    Bisected to here:

    13bc139 is the first bad commit
    commit 13bc139
    Author: Mark Shannon <mark@hotpy.org>
    Date: Thu Jan 23 09:25:17 2020 +0000

    bpo-39320: Handle unpacking of *values in compiler (GH-17984)
    
    * Add three new bytecodes: LIST_TO_TUPLE, LIST_EXTEND, SET_UPDATE. Use them to implement star unpacking expressions.
    
    * Remove four bytecodes BUILD_LIST_UNPACK, BUILD_TUPLE_UNPACK, BUILD_SET_UNPACK and  BUILD_TUPLE_UNPACK_WITH_CALL opcodes as they are now unused.
    
    * Update magic number and dis.rst for new bytecodes.
    

    In debug mode, the following code gives fails a C-level assertion:

    d = {'metaclass': type}
    for _ in [1]:
        class A(1, 2, 3, **d):
            pass

    Assertion failed: b->b_startdepth < 0 || b->b_startdepth == depth, file compile.c, line 6959

    @sweeneyde sweeneyde added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Dec 23, 2021
    @sweeneyde sweeneyde changed the title Incorrect bytecpde compilation for class class A(1, 2, 3, **d): pass gives bad bytecode Dec 23, 2021
    @sweeneyde sweeneyde added type-crash A hard crash of the interpreter, possibly with a core dump and removed build The build process and cross-build labels Dec 23, 2021
    @sweeneyde
    Copy link
    Member

    I was trying to figure out how code like this could ever not raise an exception, and here is one case that runs to completion on 3.6--3.8, but it raises TypeError: 'str' object is not callable on 3.9--3.11.

    class I(int):
        def __init__(*args, **kwargs): pass
        def __new__(*args, **kwargs): pass
    
    d = {'metaclass': I}
    class A(1, 2, 3, **d):
        pass

    @markshannon
    Copy link
    Member

    New changeset c118c24 by zq1997 in branch 'main':
    bpo-46161: Fix bug in starunpack_helper in compile.c (GH-30235)
    c118c24

    @markshannon
    Copy link
    Member

    Qiang Zhang, thanks for fixing this.

    @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.9 only security fixes 3.10 only security fixes 3.11 only security fixes type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants