[New-bugs-announce] [issue29346] datetime.utcfromtimestamp() returns strange result for very large values
report at bugs.python.org
Sun Jan 22 12:47:34 EST 2017
New submission from Eli Collins:
I've found an odd behavior when passing very large values to ``datetime.datetime.utcfromtimestamp()`` and ``.fromtimestamp()`` under python 3.6.
Under python 3.5, ``utcfromtimestamp(1<<40)`` would throw a ValueError that the year was out of range. Under python 3.6, this now returns a datetime in year 36812 (which seems reasonable given the input).
The unexpected behavior occurs when increasing the bits passed: ``utcfromtimestamp(1<<41)`` returns a datetime with a *smaller* year (6118). This pattern proceeds as the bits are increased, with the years increasing & then wrapping around again, up to the point where it exceeds time_t (at that point, python 3.6 throws the same OSError as 3.5).
It looks to me like 3.6 dropped a bounds check somewhere, and is now truncating high bits off the resulting year?
Attached is the "dump_timestamp_output.py" script that I was using to examine boundary behavior of utctimestamp() when I found this bug.
System was running Linux Mint 18.1 x86_64, using the python 3.6.0 build from https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes (ubuntu's python 3.6.0 build also shows this behavior).
components: Library (Lib)
nosy: Eli Collins
title: datetime.utcfromtimestamp() returns strange result for very large values
versions: Python 3.6
Added file: http://bugs.python.org/file46384/dump_timestamp_output.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce