Skip to content

DateFormatter crash on Windows #5202

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

Open
stevenbrix opened this issue Apr 17, 2025 · 2 comments
Open

DateFormatter crash on Windows #5202

stevenbrix opened this issue Apr 17, 2025 · 2 comments
Assignees

Comments

@stevenbrix
Copy link

After updating to a recent swift toolchain, we've noticed a new crash in our app using the following DateFormatter

let formatter = DateFormatter(dateFormat: "yyyy-MM-dd-HH-mm-ss-SSS")
formatter.locale = .init(identifier: "en_US_POSIX")
formatter.calendar = .sharedGregorian
0   Foundation.dll                  0x7ffbe99e85fa      NSTimeZone.default.setter
1   Foundation.dll                  0x7ffbe9940dd0      NSCalendar.gregorianStartDate.getter
2   Foundation.dll                  0x7ffbe99430d9      Calendar._bridgeToObjectiveC
3   Foundation.dll                  0x7ffbe98d7669      DateFormatter.Style.rawValue.getter
4   Foundation.dll                  0x7ffbe98d741b      DateFormatter.init
5   Foundation.dll                  0x7ffbe98ddf48      DateFormatter.string
FAILED_INSTRUCTION_ADDRESS: 
Foundation!Foundation::_cfObject.get+9a [D:\r\_work\swift-build\swift-build\SourceCache\swift-corelibs-foundation\Sources\Foundation\NSTimeZone.swift @ 226]
00007ffe`079885fa ??              ???

FAULTING_SOURCE_LINE:  D:\r\_work\swift-build\swift-build\SourceCache\swift-corelibs-foundation\Sources\Foundation\NSTimeZone.swift

FAULTING_SOURCE_FILE:  D:\r\_work\swift-build\swift-build\SourceCache\swift-corelibs-foundation\Sources\Foundation\NSTimeZone.swift

FAULTING_SOURCE_LINE_NUMBER:  226

FAULTING_SOURCE_CODE:  
No source found for 'D:\r\_work\swift-build\swift-build\SourceCache\swift-corelibs-foundation\Sources\Foundation\NSTimeZone.swift'
@compnerd
Copy link
Member

NSTimeZone.swift:266 :: let tz = CFTimeZoneCreateWithName(nil, name._cfObject, true)!

I suspect that CFTimeZoneCreateWithName returned nil. Assuming that name is not GMT±\d\d, this would fall back to the Windows specific path.

The path for that involves looking up the abbreviated timezone in to the Windows zone. Prior to 2973067 this would consult an external table encoded into a plist that was generated by explicitly fetching the CLDR for the release and running the associated XSLT over the data to generate the data. Failing that, we would lookup the given Olson name in the lookup in the tables, which may now be out of sync and therefore fail to find an entry. The result of the failed lookups would be that we now return NULL where we might have previously returned a value.

This might just be that the encoded table is out of sync with the current ICU that we build Foundation with. However, the tool is also designed to generate the plist and not the C array, so simply updating the table is going to be more involved.

@jmschonfeld
Copy link
Contributor

cc @iCharlesHu - yeah there's a chance that swift-foundation-icu was updated without an update to the mapping in the CF files. A more robust solution moving forwards (while we still need CF to be functional here) is to call the ICU API from CF and remove the CF mapping entirely - that's what FoundationInternationalization does now at https://github.com/swiftlang/swift-foundation/blob/edcf9ac301dca599e4f43f94e445be9511fd9396/Sources/FoundationInternationalization/TimeZone/TimeZone_ICU.swift#L320-L333

@iCharlesHu iCharlesHu self-assigned this Apr 17, 2025
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

4 participants