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

[SR-3215] CharacterSet(charactersIn: String) crashes when string contains 64 or more characters #4501

Closed
swift-ci opened this issue Nov 16, 2016 · 3 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-3215
Radar None
Original Reporter collinhundley (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, Linux, RunTimeCrash
Assignee None
Priority Medium

md5: baba1de3237b484d77abb461b9bc657a

Issue Description:

When trying to initialize a `CharacterSet` using `(charactersIn: String)`, the application crashes with a seg fault if the string contains 64 or more characters. It doesn't seem to matter what characters are included.

The issue occurs on Ubuntu 16.04 (haven't tested other versions) but does NOT occur on macOS.
Tested on Swift 3.0.1 Release and swift-DEVELOPMENT-SNAPSHOT-2016-11-12-a-ubuntu16.04

Steps to reproduce in REPL:

import Foundation
let charSet = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&+")

>> Execution interrupted.

@swift-ci
Copy link
Contributor Author

Comment by Sergey Minakov (JIRA)

The crash occurs in `CFCharacterSetAddCharactersInString` method which is called from `_CFCharacterSetInitWithCharactersInString` when string length is greater than or equal to 64.
The reason for a crash is this line (2295 atm): `CF_SWIFT_FUNCDISPATCHV(__kCFCharacterSetTypeID, void, (CFSwiftRef)theSet, NSMutableCharacterSet.addCharactersInString, theString);`.
The problem is that `__CFSwiftBridge` for `NSMutableCharacterSet` is not set.
But setting it would fail first due to cast error: Could not cast value of type 'SwiftFoundation.NSCharacterSet' to 'SwiftFoundation.NSMutableCharacterSet'.
Fix for this cast error leads to infinite loop like in https://bugs.swift.org/browse/SR-936.
Seems like the use of `_NSCFCharacterSet` in init method can fix that, but only for CharacterSet.

@swift-ci
Copy link
Contributor Author

Comment by Cyril Lashkevich (JIRA)

Seems it is fixed before 4.1

@spevans
Copy link
Collaborator

spevans commented Feb 22, 2019

Confirmed fixed in 4.1.3

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants