apple / swift-foundation

The Foundation project
Apache License 2.0
2.28k stars 135 forks source link

Overflow when calling `Calendar.date(from:)` #690

Closed itingliu closed 2 weeks ago

itingliu commented 2 weeks ago

Validate the given DateComponents values up front to align with the supported Calendar calculation date range, defined as Date.validCalendarRange.

We could alternatively guard all arithmetic operations with ...reportingOverflow, but there are too many operations, and so it seems untenable. I opted for a more realistic approach instead. _CalendarICU unconditionally truncates values to Int32, so the results for Calendar.date(from:) have always been incorrect for distant dates anyways.

Fixed 129782208

itingliu commented 2 weeks ago

@swift-ci please test