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

Assertion failure in timedelta() in case of bad __divmod__ #75933

Closed
serhiy-storchaka opened this issue Oct 10, 2017 · 12 comments
Closed

Assertion failure in timedelta() in case of bad __divmod__ #75933

serhiy-storchaka opened this issue Oct 10, 2017 · 12 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

@serhiy-storchaka
Copy link
Member

BPO 31752
Nosy @Yhg1s, @terryjreedy, @abalkin, @serhiy-storchaka, @orenmn, @mlouielu, @miss-islington
PRs
  • bpo-31752: Fix possible crash in timedelta constructor called with custom integers. #3947
  • [3.6] bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (GH-3947) #4086
  • [2.7] bpo-31752: Fix possible crash in timedelta constructor called w… #4088
  • bpo-35021: Fix assertion failures in _datetimemodule.c. #9958
  • bpo-35021: Fixes assertion failures in _datetimemodule.c #10039
  • bpo-35021: Fixes assertion failures in _datetimemodule.c #10040
  • [3.7] bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039) #10614
  • [3.6] bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039) #10615
  • [2.7] bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039) #10617
  • 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-10-23.16:57:20.973>
    created_at = <Date 2017-10-10.21:29:28.746>
    labels = ['extension-modules', '3.7', 'type-crash']
    title = 'Assertion failure in timedelta() in case of bad __divmod__'
    updated_at = <Date 2018-11-20.19:56:41.169>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2018-11-20.19:56:41.169>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-23.16:57:20.973>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2017-10-10.21:29:28.746>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31752
    keywords = ['patch']
    message_count = 12.0
    messages = ['304083', '304131', '304351', '304751', '304808', '304810', '304822', '327990', '330143', '330146', '330148', '330151']
    nosy_count = 7.0
    nosy_names = ['twouters', 'terry.reedy', 'belopolsky', 'serhiy.storchaka', 'Oren Milman', 'louielu', 'miss-islington']
    pr_nums = ['3947', '4086', '4088', '9958', '10039', '10040', '10614', '10615', '10617']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31752'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    The following code causes an assertion error in timedelta constructor.

    from datetime import timedelta
    
    class BadInt(int):
        def __mul__(self, other):
            return Prod()
    
    class Prod:
        def __radd__(self, other):
            return Sum()
    
    class Sum:
        def __divmod__(self, other):
            return (0, -1)
    
    timedelta(hours=BadInt(1))

    Result:

    python: /home/serhiy/py/cpython/Modules/_datetimemodule.c:1573: microseconds_to_delta_ex: Assertion `0 <= temp && temp < 1000000' failed.
    Aborted (core dumped)

    @serhiy-storchaka serhiy-storchaka added 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 labels Oct 10, 2017
    @mlouielu
    Copy link
    Mannequin

    mlouielu mannequin commented Oct 11, 2017

    I got a different result in latest commit: eeb5ffd

    ➜  cpython git:(master) ✗ ./python test.py
    Traceback (most recent call last):
      File "test.py", line 15, in <module>
        timedelta(hours=BadInt(1))
    SystemError: <class 'datetime.timedelta'> returned NULL without setting an error

    Do I miss some configure, I'm using ./configure --with-debug

    @terryjreedy
    Copy link
    Member

    On Win10, installed 3.5.4, 3.6.3, 3.7.1a1 all raise SystemError.
    3.6 and 3.7 repository debug builds raise AssertionError and Windows crash box. After the patch, a silent crash.

    @serhiy-storchaka
    Copy link
    Member Author

    Unpatched Python should crash in debug build and can raise SystemError in release build.

    I can't reproduce a crash on Windows after the patch.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 4ffd465 by Serhiy Storchaka in branch 'master':
    bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (bpo-3947)
    4ffd465

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 6e45d7b by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6':
    bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (GH-3947) (bpo-4086)
    6e45d7b

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 5ef883b by Serhiy Storchaka in branch '2.7':
    [2.7] bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (GH-3947) (bpo-4088)
    5ef883b

    @Yhg1s
    Copy link
    Member

    Yhg1s commented Oct 18, 2018

    This patch includes assertions that are easily triggered from user code: https://bugs.python.org/issue35021

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 3ec0f49 by Serhiy Storchaka in branch 'master':
    bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039)
    3ec0f49

    @miss-islington
    Copy link
    Contributor

    New changeset d57ab8a by Miss Islington (bot) in branch '3.7':
    bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039)
    d57ab8a

    @miss-islington
    Copy link
    Contributor

    New changeset 7a0d964 by Miss Islington (bot) in branch '3.6':
    bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039)
    7a0d964

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 40fdf47 by Serhiy Storchaka in branch '2.7':
    [2.7] bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039) (GH-10617)
    40fdf47

    @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

    4 participants