[New-bugs-announce] [issue35021] Assertion failures in datetimemodule.c.

Thomas Wouters report at bugs.python.org
Thu Oct 18 13:37:14 EDT 2018


New submission from Thomas Wouters <thomas at python.org>:

The fix for issue #31752 (changeset 5ef883b096895a84123760859f0f34ad37bf2277 for 2.7, as I ran into this while upgrading to 2.7.15) includes assertions that are easily triggered from user code:

>>> import datetime, numpy
>>> datetime.timedelta(seconds=numpy.int64(0))
python: .../Modules/datetimemodule.c:1859: accum: Assertion `_PyAnyInt_CheckExact(prod)' failed.
Aborted (core dumped)

The code asserts that the product of a known type and an unknown type is a known type, which is not a valid assumption. Pure-python reproducer (requires a build with assertions enabled, like a --with-pydebug build).

>>> import datetime
>>> class C(int):
...     def __rmul__(self, other):
...         return self
...
>>> datetime.timedelta(seconds=C())
python: .../Modules/datetimemodule.c:1859: accum: Assertion `_PyAnyInt_CheckExact(prod)' failed.
Aborted (core dumped)

(It fails in a similar way in at least Python 3.7, and since the fix was backported I'm going to assume 3.6 as well.)

Please do not use assertions for things that aren't guaranteed by the code making the assertions. These should either not be assertions, or the input types should be validated beforehand. I do not know why these assertions are being made in the first place. What do they guard against?

----------
assignee: serhiy.storchaka
components: Interpreter Core
keywords: 3.6regression, 3.7regression
messages: 327989
nosy: gregory.p.smith, serhiy.storchaka, twouters
priority: high
severity: normal
stage: needs patch
status: open
title: Assertion failures in datetimemodule.c.
type: crash
versions: Python 2.7, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35021>
_______________________________________


More information about the New-bugs-announce mailing list