classification
Title: Assertion failure in timedelta() in case of bad __divmod__
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Oren Milman, belopolsky, louielu, miss-islington, serhiy.storchaka, terry.reedy, twouters
Priority: normal Keywords: patch

Created on 2017-10-10 21:29 by serhiy.storchaka, last changed 2018-11-20 19:56 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3947 merged serhiy.storchaka, 2017-10-10 21:49
PR 4086 merged python-dev, 2017-10-23 14:12
PR 4088 merged serhiy.storchaka, 2017-10-23 15:50
PR 9958 serhiy.storchaka, 2018-10-19 11:34
PR 10039 merged serhiy.storchaka, 2018-10-22 19:54
PR 10040 open serhiy.storchaka, 2018-10-22 20:09
PR 10614 merged miss-islington, 2018-11-20 18:41
PR 10615 merged miss-islington, 2018-11-20 18:41
PR 10617 merged serhiy.storchaka, 2018-11-20 19:15
Messages (12)
msg304083 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-10 21:29
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)
msg304131 - (view) Author: Louie Lu (louielu) * Date: 2017-10-11 13:22
I got a different result in latest commit: eeb5ffd54e5

➜  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
msg304351 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-13 19:32
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.
msg304751 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-22 14:27
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.
msg304808 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-23 14:12
New changeset 4ffd4653a7ec9c97775472276cf5e159e2366bb2 by Serhiy Storchaka in branch 'master':
bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (#3947)
https://github.com/python/cpython/commit/4ffd4653a7ec9c97775472276cf5e159e2366bb2
msg304810 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-23 15:20
New changeset 6e45d7b90accbbdfef353c41ab0a78a3e4742803 by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6':
bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (GH-3947) (#4086)
https://github.com/python/cpython/commit/6e45d7b90accbbdfef353c41ab0a78a3e4742803
msg304822 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-23 16:57
New changeset 5ef883b096895a84123760859f0f34ad37bf2277 by Serhiy Storchaka in branch '2.7':
[2.7] bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (GH-3947) (#4088)
https://github.com/python/cpython/commit/5ef883b096895a84123760859f0f34ad37bf2277
msg327990 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2018-10-18 17:37
This patch includes assertions that are easily triggered from user code: https://bugs.python.org/issue35021
msg330143 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-11-20 18:41
New changeset 3ec0f495163da3b7a15deb2805cec48aed432f58 by Serhiy Storchaka in branch 'master':
bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039)
https://github.com/python/cpython/commit/3ec0f495163da3b7a15deb2805cec48aed432f58
msg330146 - (view) Author: miss-islington (miss-islington) Date: 2018-11-20 18:59
New changeset d57ab8ac182d15558118523ad1b11b029e105c46 by Miss Islington (bot) in branch '3.7':
bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039)
https://github.com/python/cpython/commit/d57ab8ac182d15558118523ad1b11b029e105c46
msg330148 - (view) Author: miss-islington (miss-islington) Date: 2018-11-20 19:02
New changeset 7a0d964afb41bde846771c81ba746238339cdd8c by Miss Islington (bot) in branch '3.6':
bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039)
https://github.com/python/cpython/commit/7a0d964afb41bde846771c81ba746238339cdd8c
msg330151 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-11-20 19:56
New changeset 40fdf471931f029ea07e6190f0fe116e0735661b by Serhiy Storchaka in branch '2.7':
[2.7] bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039) (GH-10617)
https://github.com/python/cpython/commit/40fdf471931f029ea07e6190f0fe116e0735661b
History
Date User Action Args
2018-11-20 19:56:41serhiy.storchakasetmessages: + msg330151
2018-11-20 19:15:48serhiy.storchakasetpull_requests: + pull_request9864
2018-11-20 19:02:53miss-islingtonsetmessages: + msg330148
2018-11-20 18:59:14miss-islingtonsetnosy: + miss-islington
messages: + msg330146
2018-11-20 18:41:38miss-islingtonsetpull_requests: + pull_request9861
2018-11-20 18:41:32miss-islingtonsetpull_requests: + pull_request9859
2018-11-20 18:41:12serhiy.storchakasetmessages: + msg330143
2018-10-22 20:09:05serhiy.storchakasetpull_requests: + pull_request9379
2018-10-22 19:54:58serhiy.storchakasetpull_requests: + pull_request9377
2018-10-19 11:34:58serhiy.storchakasetpull_requests: + pull_request9311
2018-10-18 17:37:34twouterssetnosy: + twouters
messages: + msg327990
2017-10-23 16:57:20serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-10-23 16:57:06serhiy.storchakasetmessages: + msg304822
2017-10-23 15:50:28serhiy.storchakasetpull_requests: + pull_request4058
2017-10-23 15:20:16serhiy.storchakasetmessages: + msg304810
2017-10-23 14:12:38python-devsetpull_requests: + pull_request4056
2017-10-23 14:12:34serhiy.storchakasetmessages: + msg304808
2017-10-22 14:27:41serhiy.storchakasetmessages: + msg304751
2017-10-13 19:32:13terry.reedysetnosy: + terry.reedy
messages: + msg304351
2017-10-11 13:22:30louielusetnosy: + louielu
messages: + msg304131
2017-10-10 21:49:17serhiy.storchakasetkeywords: + patch
pull_requests: + pull_request3922
2017-10-10 21:29:28serhiy.storchakacreate