Skip to content

time: unchecked overflow in Add and AddDays #20678

@bcmills

Description

@bcmills

I'm trying to define a mapping between time.Time and a C++ time library.

The library that I'm trying to map to supports distinct "infinite past" and "infinite future" times, which need to be mapped to distinct time.Time values. The logical choices would seem to be the maximum and minimum representable time.Time values.

One way to try to obtain those is to call (time.Time).AddDate with absurdly positive or absurdly negative values. AddDate does not return an error, and it cannot reasonably panic on overflow (because the package does not define a way for users to check for such an overflow ahead of time). That leaves one "obvious" behavior: saturation.

Sadly, the current implementation fails to provide that behavior, and instead silently overflows to nonsensical values (https://play.golang.org/p/UUC2JG7Xcj).

(Further evidence for #19624?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions