Skip to content

int overflow in datetime causes seg fault from datetime.ctime() #54097

Closed

Description

@bernie9998
BPO 9888
Nosy @warsaw, @amauryfa, @mdickinson, @abalkin, @pitrou, @bitdancer
Superseder
  • bpo-7150: datetime operations spanning MINYEAR give bad results
  • Files
  • segfault.py: sample code as a simple script, when executed segmentation fault occurs
  • segfault.py: updated demonstration script relative to current date, shows all edge cases until segmentation fault.
  • 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 2010-09-23.22:31:45.460>
    created_at = <Date 2010-09-17.18:18:00.366>
    labels = ['type-crash']
    title = 'int overflow in datetime causes seg fault from datetime.ctime()'
    updated_at = <Date 2010-09-23.22:31:45.458>
    user = 'https://bugs.python.org/bernie9998'

    bugs.python.org fields:

    activity = <Date 2010-09-23.22:31:45.458>
    actor = 'amaury.forgeotdarc'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-09-23.22:31:45.460>
    closer = 'amaury.forgeotdarc'
    components = ['None']
    creation = <Date 2010-09-17.18:18:00.366>
    creator = 'bernie9998'
    dependencies = []
    files = ['18909', '18910']
    hgrepos = []
    issue_num = 9888
    keywords = []
    message_count = 5.0
    messages = ['116700', '116712', '116723', '116767', '117243']
    nosy_count = 7.0
    nosy_names = ['barry', 'amaury.forgeotdarc', 'mark.dickinson', 'belopolsky', 'pitrou', 'r.david.murray', 'bernie9998']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = '7150'
    type = 'crash'
    url = 'https://bugs.python.org/issue9888'
    versions = ['Python 2.6']

    Activity

    1. bernie9998 commented on Sep 17, 2010

      bernie9998mannequin
      MannequinAuthor

      When creating an int overflow via a subtraction operation with a datetime object and a timedelta object, the resulting datetime object can cause a segmentation fault when the ctime method is called.

      Segmentation Fault occurred on python 2.6.5 on 64 bit ubuntu lucid.

      Code as follows:

      from datetime import datetime, timedelta
      (datetime.now() - timedelta(734395)).ctime()
    2. added
      type-crash
      on Sep 17, 2010
    3. bitdancer commented on Sep 17, 2010

      @bitdancer
      Member

      This does not reproduce for me on python2.6.5 gentoo linux; however, gentoo linux does have some additional post 2.6.5 patches applied.
      It also does not reproduce on 2.7.

    4. bernie9998 commented on Sep 17, 2010

      bernie9998mannequin
      MannequinAuthor

      After further investigation, it appears the cause is the ability to overflow the datetime object by almost a year. I've modified the test to demonstrate this relative to the current date:

      from datetime import date, datetime, timedelta
      (datetime.now()-timedelta((date.today()-date(1,1,1)).days+364)).ctime()

      It seems the date can be overflowed by up to a year without throwing an Exception. The result of which is a seg fault when calling the bound ctime method.

      Note that anything above 364 results in OverFlowError. Below 18 still overflows, but does not seg fault, instead resulting in a weird result,e.g.:
      'Tue (null) 240 17:25:37 0001'

      I'll update the script to demonstrate the edge cases where this occurs.

    5. pitrou commented on Sep 18, 2010

      @pitrou
      Member

      Apparently it has been fixed somewhere between 2.6.5 and 2.6.6. I get a segmentation fault in 2.6.5, but an OverflowError in all of {2.6.6, 2.7, 3.1, 3.2}.

    6. amauryfa commented on Sep 23, 2010

      @amauryfa
      Contributor

      yes, this was fixed by bpo-7150.

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      type-crash

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions