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

SIGTRAP Crash when creating a Date from DateComponents with nanosecond >=1 second #4814

Open
lovetodream opened this issue Aug 29, 2023 · 0 comments

Comments

@lovetodream
Copy link

If you create a Date from DateComponents via Calendar and the DateComponents' nanosecond property is equal to or more than a full second, you'll get a SIGTRAP crash.

Example:

let year = 2023
let month = 8
let day = 27
let hour = 19
let minute = 30
let second = 48
let nanosecond = Int(1.2 * 1_000_000_000) // change 1.2 to anything below 1.0 and it won't crash
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
let components = DateComponents(
    calendar: calendar,
    year: year,
    month: month,
    day: day,
    hour: hour,
    minute: minute,
    second: second,
    nanosecond: nanosecond
)
let value = calendar.date(from: components)

Stack trace:

function signature specialization <Arg[4] = Dead> of Foundation.NSCalendar._convert(_: Swift.Optional<Swift.Int>, type: Swift.String, vector: inout Swift.Array<Swift.Int32>, compDesc: inout Swift.Array<Swift.Int8>) -> () (@function signature specialization <Arg[4] = Dead> of Foundation.NSCalendar._convert(_: Swift.Optional<Swift.Int>, type: Swift.String, vector: inout Swift.Array<Swift.Int32>, compDesc: inout Swift.Array<Swift.Int8>) -> ():22)
function signature specialization <Arg[1] = Dead> of Foundation.NSCalendar._convert(Foundation.DateComponents) -> (Swift.Array<Swift.Int32>, Swift.Array<Swift.Int8>) (@function signature specialization <Arg[1] = Dead> of Foundation.NSCalendar._convert(Foundation.DateComponents) -> (Swift.Array<Swift.Int32>, Swift.Array<Swift.Int8>):171)
Foundation.NSCalendar.date(from: Foundation.DateComponents) -> Swift.Optional<Foundation.Date> (@Foundation.NSCalendar.date(from: Foundation.DateComponents) -> Swift.Optional<Foundation.Date>:13)
partial apply forwarder for closure #1 (Foundation.NSCalendar) -> Swift.Optional<Foundation.Date> in Foundation.Calendar.date(from: Foundation.DateComponents) -> Swift.Optional<Foundation.Date> (@partial apply forwarder for closure #1 (Foundation.NSCalendar) -> Swift.Optional<Foundation.Date> in Foundation.Calendar.date(from: Foundation.DateComponents) -> Swift.Optional<Foundation.Date>:15)
Foundation._MutableHandle.map<τ_0_0>((τ_0_0) throws -> τ_1_0) throws -> τ_1_0 (@Foundation._MutableHandle.map<τ_0_0>((τ_0_0) throws -> τ_1_0) throws -> τ_1_0:25)
Foundation.Calendar.date(from: Foundation.DateComponents) -> Swift.Optional<Foundation.Date> (@Foundation.Calendar.date(from: Foundation.DateComponents) -> Swift.Optional<Foundation.Date>:20)

The same code works fine on macOS. Related Swift Forums post: https://forums.swift.org/t/crash-on-linux-when-creating-a-date-from-calendar-date-from-datecomponents/66988

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant