Uploaded image for project: 'Swift'
  1. Swift
  2. SR-3509

Foundation CharacterSet Crash

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Foundation
    • Labels:
    • Environment:

      {{xcodebuild -version
      Xcode 8.2
      Build version 8C38}}

      {{swift --version
      Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
      Target: x86_64-apple-macosx10.9}}

      Description

      The following code causes a crash in foundation at runtime:

      var set = CharacterSet()
      set.insert("\u{D7FF}") // no crash
      set.insert("\u{D7FF}") // no crash
      set.insert(charactersIn: "\u{D7FE}"..."\u{D7FF}") // crashes
      

      According to the UnicodeScalar.init(_:UInt32) source, 0xD7FF is a valid character:

          //     * As a result of this definition, the set of Unicode scalar values
          //     consists of the ranges 0 to D7FF and E000 to 10FFFF, inclusive.
      

      https://github.com/apple/swift/blob/2fe4254cb712fa101a220f95b6ade8f99f43dc74/stdlib/public/core/UnicodeScalar.swift#L97

      I suspect there is an edge case where 0xD7FF is accidentally excluded.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            bnut Andrew Bennett
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: