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-1930] Passing an invalid value to UnicodeScalar initializer crashes the app #44539

Closed
swift-ci opened this issue Jun 29, 2016 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1930
Radar rdar://problem/24110013
Original Reporter dunkelstern (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

Tested on Xcode Version 7.3.1 (7D1014), but happens in newer versions too.

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, swift-evolution-proposal-needed
Assignee 酷酷的哀殿 (JIRA)
Priority Medium

md5: 55ec1ebb5dd1238e7abbe723f7df69c9

Issue Description:

What happens:

When you pass an invalid value to the UnicodeScalar initializer the swift stdlib crashes the program by calling _precondition this is bad if you construct a unicode scalar from user input (e.g. JSON parser)

Example:

var string = ""
let codepoint: UInt32 = 55357 // this is invalid
string.append(UnicodeScalar(codepoint))

What do I expect:

Either the initializer is non-failable or it should be marked as failable and throw an error, but crashing the whole app seems like a bad idea. The documentation states:

Requires: v is a valid Unicode scalar value.

But it does in no way mention that the app will crash otherwise.

NOTE: Requires a swift-evolution proposal.

@belkadan
Copy link
Contributor

In all cases violating a "Requires" precondition means the app may crash. Should this initializer be failable, though, @gribozavr? It's hard to validate whether something is a good UnicodeScalar without having access to a Unicode table.

@gribozavr
Copy link
Collaborator

Yes, this initializer should be failable.

@Dante-Broggi
Copy link
Contributor

I think this bug should be closed as `Unicode.Scalar(UInt32)` is now failable.

@swift-ci
Copy link
Collaborator Author

Comment by bohong sun (JIRA)

`Unicode.Scalar(UInt32)` is now failable.

This is a sample.

```

var string = ""

let codepoint: UInt32 = 55357 // this is invalid

string.append(String(UnicodeScalar(codepoint) ?? "\u{61}"))

```

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

4 participants