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

Double decref and dereferencing after decref in int() #60264

Closed
serhiy-storchaka opened this issue Sep 27, 2012 · 12 comments
Closed

Double decref and dereferencing after decref in int() #60264

serhiy-storchaka opened this issue Sep 27, 2012 · 12 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@serhiy-storchaka
Copy link
Member

BPO 16060
Nosy @birkenfeld, @jcea, @mdickinson, @benjaminp, @serhiy-storchaka
Files
  • float2int_dbl_decref.patch
  • float2int_dbl_decref_2.patch
  • 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 = 'https://github.com/mdickinson'
    closed_at = <Date 2012-09-28.13:35:29.207>
    created_at = <Date 2012-09-27.08:46:57.883>
    labels = ['interpreter-core', 'type-crash']
    title = 'Double decref and dereferencing after decref in int()'
    updated_at = <Date 2012-09-29.07:27:39.936>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2012-09-29.07:27:39.936>
    actor = 'python-dev'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2012-09-28.13:35:29.207>
    closer = 'georg.brandl'
    components = ['Interpreter Core']
    creation = <Date 2012-09-27.08:46:57.883>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['27316', '27319']
    hgrepos = []
    issue_num = 16060
    keywords = ['patch']
    message_count = 12.0
    messages = ['171371', '171376', '171380', '171382', '171383', '171385', '171386', '171388', '171415', '171424', '171461', '171556']
    nosy_count = 6.0
    nosy_names = ['georg.brandl', 'jcea', 'mark.dickinson', 'benjamin.peterson', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue16060'
    versions = ['Python 3.3']

    @serhiy-storchaka
    Copy link
    Member Author

    In function convert_integral_to_int() in file Objects/abstract.c integral double decrefed and dereferenced after decrefing if returned value of __int__() is not int. Python 3.3 only affected.

    Here is a patch.

    @serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Sep 27, 2012
    @mdickinson
    Copy link
    Member

    Nice catch! And indeed, the following code generates a segfault on my machine:

        class B(object):
            def __int__(self):
                return 43.0
    
        class A(object):
            def __trunc__(self):
                return B()
    
        int(A())

    The patch should probably include a regression test.

    @serhiy-storchaka
    Copy link
    Member Author

    And indeed, the following code generates a segfault on my machine:

    I was going to give similar example and assign crash type to issue, but on my machine it does not generate a segfault.

    The patch should probably include a regression test.

    Someone borrowed Guido's time machine and have already done this test (see NonIntegral in Lib/test/test_int.py).

    @mdickinson
    Copy link
    Member

    That test doesn't look quite the same, though: the return value of __trunc__ is an object that has __trunc__ rather than __int__. And all the existing tests pass on my machine without issues.

    @mdickinson
    Copy link
    Member

    Here's patch that adds a regression test.

    @serhiy-storchaka
    Copy link
    Member Author

    Ah, it generates a segfault in debug mode.

    LGTM.

    @serhiy-storchaka serhiy-storchaka added type-crash A hard crash of the interpreter, possibly with a core dump and removed type-bug An unexpected behavior, bug, or error labels Sep 27, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 27, 2012

    New changeset 690287f8ea95 by Mark Dickinson in branch 'default':
    Issue bpo-16060: Fix a double DECREF in int() implementation. Thanks Serhiy Storchaka.
    http://hg.python.org/cpython/rev/690287f8ea95

    @mdickinson
    Copy link
    Member

    Applied. Thanks!

    I'm not sure whether this is worthy of inclusion in Python 3.3.0; on one hand, it's a segfault from core Python. On the other, it doesn't look that easy to trigger by accident.

    On balance, I'd say it's safe to wait for Python 3.3.1 for this. Adding Georg to the nosy in case he disagrees.

    @mdickinson mdickinson self-assigned this Sep 27, 2012
    @jcea
    Copy link
    Member

    jcea commented Sep 28, 2012

    Serhiy, I wonder how you found this :)

    @serhiy-storchaka
    Copy link
    Member Author

    Serhiy, I wonder how you found this :)

    I just looked at the code for bpo-16036.

    @birkenfeld
    Copy link
    Member

    Applied: d23eb81bd482.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 29, 2012

    New changeset d23eb81bd482 by Mark Dickinson in branch 'default':
    Issue bpo-16060: Fix a double DECREF in int() implementation. Thanks Serhiy Storchaka.
    http://hg.python.org/cpython/rev/d23eb81bd482

    @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

    4 participants