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

[SR-10038] Runtime crash in DateInterval.hashValue on dates before the reference date #3522

Closed
swift-ci opened this issue Mar 4, 2019 · 3 comments

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Mar 4, 2019

Previous ID SR-10038
Radar None
Original Reporter fastred (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.14.3 (18D109), Xcode 10.2 beta 3 (10P99q)

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 98da45bd6998a1ea31621ea1cc7b8bf3

Issue Description:

The following code:

let dateInterval = DateInterval(start: Date(timeIntervalSinceReferenceDate: -1), duration: 1)
let hash = dateInterval.hashValue

crashes in runtime due to casting negative value of Double to UInt on this line: https://github.com/apple/swift/blob/6e7051eb1e38e743a514555d09256d12d3fec750/stdlib/public/Darwin/Foundation/DateInterval.swift#L159

There's what seems to be an abandoned PR for exactly this bug: apple/swift#20106

@belkadan
Copy link

belkadan commented Mar 4, 2019

cc @millenomi

@swift-ci
Copy link
Contributor Author

Comment by August S. Freytag (JIRA)

I've also found it by storing date intervals in the 80s. It's dangerous how you can run into it, just by inserting any data structure into a set that has a date interval someplace, invoking hashValue implicitly.

@swift-ci
Copy link
Contributor Author

swift-ci commented May 2, 2020

Comment by August S. Freytag (JIRA)

Tested and fixed as of macOS 10.15.4.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants