Skip to content

pytime.c:184 and pytime.c:218: runtime error, outside the range of representable values of type 'long' #65140

Description

@JeffreyWalton
BPO 20941
Nosy @vstinner, @gareth-rees, @vadmium
Superseder
  • bpo-31373: demoting floating float values to unrepresentable types is undefined behavior
  • 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 2018-05-22.13:33:25.714>
    created_at = <Date 2014-03-15.21:48:45.694>
    labels = ['tests']
    title = "pytime.c:184 and pytime.c:218: runtime error, outside the range of representable values of type 'long'"
    updated_at = <Date 2018-05-22.13:33:25.713>
    user = 'https://bugs.python.org/JeffreyWalton'

    bugs.python.org fields:

    activity = <Date 2018-05-22.13:33:25.713>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-05-22.13:33:25.714>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2014-03-15.21:48:45.694>
    creator = 'Jeffrey.Walton'
    dependencies = []
    files = []
    hgrepos = ['223']
    issue_num = 20941
    keywords = []
    message_count = 8.0
    messages = ['213686', '213756', '213760', '213910', '317089', '317090', '317091', '317278']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'gdr@garethrees.org', 'martin.panter', 'Jeffrey.Walton']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '31373'
    type = None
    url = 'https://bugs.python.org/issue20941'
    versions = ['Python 3.5']

    Activity

    1. JeffreyWalton commented on Mar 15, 2014

      JeffreyWaltonmannequin
      MannequinAuthor

      pytime.c:184: runtime error: value -1e+200 is outside the range of representable values of type 'long'

      and

      pytime.c:218: runtime error: value -1e+200 is outside the range of representable values of type 'long'

      It appears the cast on 'intpart' is generating the finding. 'intpart' is a double.

          *sec = (time_t)intpart;
          err = intpart - (double)*sec;
          if (err <= -1.0 || err >= 1.0) {
              error_time_t_overflow();
              return -1;
          }

      Shouldn't a range test based on TIME_T_MAX with an epsilon occur first?

    2. vstinner commented on Mar 16, 2014

      @vstinner
      Member

      Hi,

      pytime.c:184: runtime error: value -1e+200 is outside the range of representable values of type 'long'

      How did you get this warning?

      Shouldn't a range test based on TIME_T_MAX with an epsilon occur first?

      Two lines after, the integer overflow is checked:

              *sec = (time_t)intpart;
              err = intpart - (double)*sec;
              if (err <= -1.0 || err >= 1.0) {
                  error_time_t_overflow();
                  return -1;
              }

      And it works, example:

      >>> import _testcapi
      >>> _testcapi.pytime_object_to_time_t(-1e+200, 0)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      OverflowError: timestamp out of range for platform time_t

      (where 0 means _PyTime_ROUND_DOWN)

    3. gareth-rees commented on Mar 16, 2014

      gareth-reesmannequin
      Mannequin

      How did you get this warning?

      This looks like runtime output from a program built using Clang/LLVM with -fsanitize=undefined. See here: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation

      Signed integer overflow is undefined behaviour, so by the time *sec = (time_t)intpart has been evaluated, the undefined behaviour has already happened. It is too late to check for it afterwards.

    4. vstinner commented on Mar 17, 2014

      @vstinner
      Member

      Shouldn't a range test based on TIME_T_MAX with an epsilon occur first?

      What is this constant? I don't see it in Python source code.

    5. vadmium commented on May 19, 2018

      @vadmium
      Member

      Maybe worth checking if this is fixed due to the changes in bpo-31373 for 3.6+.

    6. vstinner commented on May 19, 2018

      @vstinner
      Member

      "resolution: out of date"

      Is this issue fixed or not? It's still open.

    7. vadmium commented on May 19, 2018

      @vadmium
      Member

      I don’t know; I haven’t tested it. I was anticipating that it is fixed, but perhaps I should leave the resolution alone instead?

    8. vstinner commented on May 22, 2018

      @vstinner
      Member

      I close the issue as a duplicate of bpo-31373. Reopen/comment bpo-31373 if the issue is not completely fixed.

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

      testsTests in the Lib/test dir

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions