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

crashes in multiply_float_timedelta() and in truedivide_timedelta_float() #75474

Closed
orenmn mannequin opened this issue Aug 28, 2017 · 7 comments
Closed

crashes in multiply_float_timedelta() and in truedivide_timedelta_float() #75474

orenmn mannequin opened this issue Aug 28, 2017 · 7 comments
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@orenmn
Copy link
Mannequin

orenmn mannequin commented Aug 28, 2017

BPO 31293
Nosy @abalkin, @serhiy-storchaka, @orenmn
PRs
  • bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method #3227
  • [3.6] bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method. (GH-3227) #3654
  • 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 2017-09-19.14:01:15.912>
    created_at = <Date 2017-08-28.14:36:40.195>
    labels = ['extension-modules', '3.7', 'type-crash']
    title = 'crashes in multiply_float_timedelta() and in truedivide_timedelta_float()'
    updated_at = <Date 2017-09-19.14:01:15.910>
    user = 'https://github.com/orenmn'

    bugs.python.org fields:

    activity = <Date 2017-09-19.14:01:15.910>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-09-19.14:01:15.912>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2017-08-28.14:36:40.195>
    creator = 'Oren Milman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31293
    keywords = ['patch']
    message_count = 7.0
    messages = ['300954', '300955', '300956', '300957', '300958', '302520', '302528']
    nosy_count = 3.0
    nosy_names = ['belopolsky', 'serhiy.storchaka', 'Oren Milman']
    pr_nums = ['3227', '3654']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31293'
    versions = ['Python 3.6', 'Python 3.7']

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Aug 28, 2017

    both of the following true division and multiplication operations crash the
    interpreter:

    import datetime
    
    class BadFloat(float):
        def as_integer_ratio(self):
            return (1 << 1000) - 1

    datetime.timedelta() / BadFloat()
    datetime.timedelta() * BadFloat()

    this is because both multiply_float_timedelta() and truedivide_timedelta_float()
    (in Modules/_datetimemodule.c) assume as_integer_ratio() returns tuple.

    @orenmn orenmn mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.7 (EOL) end of life type-crash A hard crash of the interpreter, possibly with a core dump labels Aug 28, 2017
    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Aug 28, 2017
    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Aug 28, 2017

    i am working on a patch.

    BTW, is there anywhere a list of what counts as an extension
    module, and what counts as the interpreter core?

    @serhiy-storchaka
    Copy link
    Member

    I don't know if there is a list, but definitely the parser, the compiler, the evaluation loop, builtin types and few builtin modules (like builtins and sys) are interpreter core. The _datetime module is an accelerator of the datetime module. It is optional and definitely is not in the core.

    @serhiy-storchaka
    Copy link
    Member

    Please check if there is similar issue with Decimal.

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Aug 28, 2017

    I guess you meant for me to check whether the following has any problem:
    import decimal

    class BadFloat(float):
        def as_integer_ratio(self):
            return 1 << 1000
    
    decimal.Decimal.from_float(BadFloat())

    so it doesn't crash.
    if IIUC, this is because the C implementation of Decimal.from_float()
    is PyDecType_FromFloat(), while the relevant part of it is a call to
    PyDecType_FromFloatExact().
    But PyDecType_FromFloatExact() uses float.as_integer_ratio(), and thus
    ISTM that the issue doesn't exist there.

    (also, the following doesn't raise an exception, as expected:
    import decimal

    class BadFloat(float):
        def as_integer_ratio(self):
            raise RuntimeError
    
    decimal.Decimal.from_float(BadFloat())
    )

    @serhiy-storchaka
    Copy link
    Member

    New changeset 865e4b4 by Serhiy Storchaka (Oren Milman) in branch 'master':
    bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method. (bpo-3227)
    865e4b4

    @serhiy-storchaka
    Copy link
    Member

    New changeset f37dd11 by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6':
    [3.6] bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method. (GH-3227) (bpo-3654)
    f37dd11

    @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 extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant