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-3667] Crash in CharacterSet #4295

Open
swift-ci opened this issue Jan 18, 2017 · 4 comments
Open

[SR-3667] Crash in CharacterSet #4295

swift-ci opened this issue Jan 18, 2017 · 4 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-3667
Radar None
Original Reporter aamctustwo (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 8.2
macOS 10.12.2

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 6883edae0bb5e9e44b987df04957b303

Issue Description:

There is a crash in the CharacterSet implementation. See the example below. I've attached a Playground with this issue and a screenshot of the error.

import Foundation

extension CharacterSet {
    func isSuperset(ofCharactersIn string: String) -> Bool {
        let otherSet = CharacterSet(charactersIn: string)
        return isSuperset(of: otherSet)
    }
}

let foo = "_"

let bar = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: foo))

print(bar.isSuperset(ofCharactersIn: foo))
@swift-ci
Copy link
Contributor Author

swift-ci commented May 3, 2017

Comment by Nathaniel Bomberger (JIRA)

Some observations that may be helpful: I was able to reproduce this bug intermittently. For example, it seemed if I restarted playground and enterered in your code, it would occur. If I changed the characters, it might crash at first, then it would work, however, then it would seem to work correctly after deleting some text in playground. It felt very racy.. or perhaps some underlying memory mishandle?

it should be noted I am on the Xcode 8.3.2, Swift 3.1. Sierra 10.12.5, and it still exists.

@swift-ci
Copy link
Contributor Author

swift-ci commented May 3, 2017

Comment by Nathaniel Bomberger (JIRA)

Possibly related to SR-3485, SR-2510, SR-2509

@CharlesJS
Copy link

I'm thinking it's a memory error, because I intermittently get either crashes or incorrect results with the following code, but it reliably crashes once I turn Guard Malloc on:

{code:none}import Foundation

let charset1 = CharacterSet(charactersIn: "abc")
let charset2 = CharacterSet(charactersIn: "a")

// returns 'false' with Guard Malloc off, crashes with Guard Malloc on
print(charset1.isSuperset(of: charset2))

@CharlesJS
Copy link

Also, this workaround seems to work: copy the charsets so that they become good old C/ObjC __NSCFCharacterSets instead of _SwiftNSCharacterSet, and then use CoreFoundation to prevent the bridge from bringing things back:

import Foundation

let charset1 = (CharacterSet(charactersIn: "abc") as NSCharacterSet).copy() as! CFCharacterSet
let charset2 = (CharacterSet(charactersIn: "a") as NSCharacterSet).copy() as! CFCharacterSet

print(CFCharacterSetIsSupersetOfSet(charset1, charset2)) // true

@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
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