[New-bugs-announce] [issue34423] Overflow when casting from double to time_t, and_PyTime_t.
report at bugs.python.org
Fri Aug 17 17:56:49 EDT 2018
New submission from Michał Radwański <lisklusownik at gmail.com>:
Code triggering bug:
time.sleep(2**63 / 10**9)
ValueError: sleep length must be non-negative
The problem is with the macro that checks the range of provided double:
Line 228 of Include/pymath.h:
#define _Py_InIntegralTypeRange(type, v) (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
The type here is _PyTime_t, which is a typedef to int64_t.
Proposed solution is to change <= into <, since float(2**63-1) == float(2**63), and that means that none double can ever be equal to 2**63-1.
components: Interpreter Core
nosy: belopolsky, enedil, lemburg, vstinner
title: Overflow when casting from double to time_t, and_PyTime_t.
versions: Python 3.6, Python 3.7, Python 3.8
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce