Open swift-ci opened 5 years ago
@Catfish-Man , any ideas here?
Guessing that was meant for (a different) @Catfish-Man?
Yeah. I'm going to look into this today most likely.
The primary change in NSPathStore2 between those releases was to support CFStringGetCharactersPtr, so presumably this is something that occurs on the non-contiguous path. I'll see if I can force that to happen on a newer system with a different string subclass.
Hmm. That hypothesis doesn't hold for NSBigMutableString though.
I believe this is fixed in https://github.com/apple/swift/pull/27779
Will attempt to confirm soon
Environment
Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7) Target: x86_64-apple-darwin18.7.0 macOS: 10.14.6 (18G95) Xcode: 11.1 (11A1027)Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 1 | |Component/s | Foundation | |Labels | Bug | |Assignee | @Catfish-Man | |Priority | Medium | md5: aa68f9cc8ccaab9b757ab0270295576dIssue Description:
Description
An
NSRangeException
arises and the application crashes when getting substring with a Swift range via subscript brackets from a specific Foundation's inner string class instance.This issue occurs only when a compile optimization is enabled and under macOS 10.14. When runs the code without optimization or under macOS 10.15, it works correctly (I haven't tried macOS 10.13 or other environments yet).
Furthermore, if the same code is written in Objective-C it works even under the same conditions. So, something would go wrong with the range translation between Swift \<-> ObjC.
Conditions
The conditions I found so far to reproduce this phenomenon are:
The execution environment is macOS 10.14 (not macOS 10.15).
Optimization
-O
is enabled.The actual string instance class is not a pure
Swift.String
or__NSCFString
butNSPathStore2
orNSBigMutableString
at least.The range to obtain substring contains the last index.
The range to obtain substring was made from a Foundation method (not like
string.startIndex..<string.endIndex
).Obtaining substring with
Range<String.Index>
via subscript (notPartialRangeFrom<String.Index>
).In addition, the same code works when I used Xcode 10.3 with Swift 5. But I'm not sure from when (from Xcode 11, 11.1, or from Swift 5.1?) it has been broken.
If not satisfy one of those conditions, the code works as excepted without throwing any exception.
Expected Result
Succeed in obtaining substring without any exception.
Steps to Reproduce the Issue
The followings are sample codes to reproduce those issues.
Run it with
-O
option under macOS 10.14.x.It will crash due to an NSRangeException.
Sample code for NSPathStore2
Sample code for NSBigMutableString