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

datetime doesn't check for min/max dates anymore in Python 3.6.0 => crash #73532

Closed
eli-collins mannequin opened this issue Jan 22, 2017 · 5 comments
Closed

datetime doesn't check for min/max dates anymore in Python 3.6.0 => crash #73532

eli-collins mannequin opened this issue Jan 22, 2017 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@eli-collins
Copy link
Mannequin

eli-collins mannequin commented Jan 22, 2017

BPO 29346
Nosy @malemburg, @abalkin, @vstinner, @eli-collins
Superseder
  • bpo-29100: datetime.fromtimestamp() doesn't check min/max year anymore: regression of Python 3.6
  • Files
  • dump_timestamp_output.py
  • 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-01-27.14:58:10.215>
    created_at = <Date 2017-01-22.17:47:34.476>
    labels = ['type-bug', 'library']
    title = "datetime doesn't check for min/max dates anymore in Python 3.6.0 => crash"
    updated_at = <Date 2017-01-27.14:58:10.213>
    user = 'https://github.com/eli-collins'

    bugs.python.org fields:

    activity = <Date 2017-01-27.14:58:10.213>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-01-27.14:58:10.215>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2017-01-22.17:47:34.476>
    creator = 'Eli Collins'
    dependencies = []
    files = ['46384']
    hgrepos = []
    issue_num = 29346
    keywords = ['3.6regression']
    message_count = 5.0
    messages = ['286021', '286025', '286034', '286091', '286360']
    nosy_count = 4.0
    nosy_names = ['lemburg', 'belopolsky', 'vstinner', 'Eli Collins']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '29100'
    type = 'behavior'
    url = 'https://bugs.python.org/issue29346'
    versions = ['Python 3.6']

    @eli-collins
    Copy link
    Mannequin Author

    eli-collins mannequin commented Jan 22, 2017

    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).

    @eli-collins eli-collins mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 22, 2017
    @malemburg
    Copy link
    Member

    According to the datetime.h file, the valid range for year is 1-9999, so it's a bit surprising that Python 3.6 allows dates outside this range.

    Internally, the year is represented using 2 bytes, so you could represent years outside the range and up to 65535 as well.

    Here's what mxDateTime outputs for the given timestamps:

     >>> from mx.DateTime import *
     >>> DateTimeFromTicks(1<<40)
    <mx.DateTime.DateTime object for '36812-02-20 01:36:16.00' at 7f17a38a2390>
     >>> DateTimeFromTicks(1<<41)
    <mx.DateTime.DateTime object for '71654-04-10 03:12:32.00' at 7f17a1bdf858>

    @abalkin
    Copy link
    Member

    abalkin commented Jan 22, 2017

    This looks like a duplicate of issue bpo-29100 ("datetime.fromtimestamp() doesn't check min/max year anymore: regression of Python 3.6").

    @eli-collins
    Copy link
    Mannequin Author

    eli-collins mannequin commented Jan 23, 2017

    My apologies, I think Alexander is right, this is a duplicate of bpo-29100

    I'd seen the first message in that issue talking about a core dump, and thought this was different problem; but I see the scope of the issue broadened to cover general bounds issues in later messages.

    Reviewing the fix & the tests from that issue's patches, it looks like exactly this case.

    @vstinner vstinner changed the title datetime.utcfromtimestamp() returns strange result for very large values datetime doesn't check for min/max dates anymore in Python 3.6.0 => crash Jan 27, 2017
    @vstinner
    Copy link
    Member

    Since it's a duplicate, I close this issue.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants