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-8939] "this should not happen" panic when putting unicode in a Map #51444

Closed
swift-ci opened this issue Oct 7, 2018 · 9 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 7, 2018

Previous ID SR-8939
Radar rdar://problem/45216800
Original Reporter stestagg (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Behaviour seen in:

  • Version 10.1 beta (10O23u)

    • IOS simulator test runner

    • swift playgrounds

  • Version 10.0 (10A255)

    • IOS simulator test runner

Swift 4

Additional Detail from JIRA
Votes 2
Component/s Standard Library
Labels Bug
Assignee Lance (JIRA)
Priority Medium

md5: 7876f9cdec20fa38565934d4afecb1fd

is blocked by:

  • SR-9048 Intentionally crafted String can crash Swift application by fatalError

relates to:

  • SR-9048 Intentionally crafted String can crash Swift application by fatalError

Issue Description:

The following code:

import UIKit
var map: [String: CGFloat] = [:]
func randomUnicodeCharacter() -> String {
    let i = arc4random_uniform(1114111)
    return (i > 55295 && i < 57344) ? randomUnicodeCharacter() : String(UnicodeScalar(i)!)
}
func randomUnicodeString(_ length: UInt32) -> String {
    return (0..<length).map{_ in randomUnicodeCharacter()}.joined()
}

while true {
    map[randomUnicodeString(50)] = 1.0  // <- fails here
}

Typically fails after ~3000 - 10000 iterations, with the error:

Fatal error: Output buffer was not big enough, this should not happen: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang_Fall2018/swiftlang_Fall2018-1000.11.40/src/swift/stdlib/public/core/NormalizedCodeUnitIterator.swift, line 177 

While it may be possible that some invalid strings are being generated, it's surprising that the quoted error is raised, and raised on the indicated line.

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Oct 12, 2018

CC @milseman

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Oct 12, 2018

@swift-ci create

@milseman
Copy link
Mannequin

milseman mannequin commented Oct 12, 2018

CC Lance (JIRA User)

@swift-ci
Copy link
Collaborator Author

Comment by Daniel Alm (JIRA)

I am seeing the same behavior with another string occurring in real life (it was part of an email subject). I would paste that string here, but I am afraid it actually causes Jira to throw an exception.

My app's users are affected by this crash. Lance (JIRA User), do you happen to know when a fix could become available?

@milseman
Copy link
Mannequin

milseman mannequin commented Dec 11, 2018

This was fixed on master and 5.0 a couple weeks back. Lance (JIRA User) can you link the PR?

@swift-ci
Copy link
Collaborator Author

Comment by Kirk Beitz (JIRA)

any chance the bug is something that could be fixed in a point release to go into an upcoming Xcode? or is that not a possibility?

@swift-ci
Copy link
Collaborator Author

Comment by Lance Parker (JIRA)

Here's the PR against master: #20585

This will be fixed in 5.0 which releases in the spring. I'm not sure if there's a way to get the fix into an earlier release but I can look into it.

@swift-ci
Copy link
Collaborator Author

Comment by Daniel Alm (JIRA)

Lance (JIRA User) thanks for the info. It would be appreciated if you could check if this could go into a possible Swift 4.2.2 in a possible Xcode 10.2 or 10.1.1.

Alternatively, would it at least be possible to backport this to the Swift 4.2 branch, so that we can use the nightly Swift 4.2 branch builds to create a fixed binary for the affected users?

@swift-ci
Copy link
Collaborator Author

Comment by Lance Parker (JIRA)

Unfortunately we aren't putting any fixes into the 4.2 branch anymore (and it wouldn't help for App Store apps anyway since you can't ship to there from a toolchain).

The fix is in the latest 5.0 toolchain and you can try that out if you'd like.

@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
Projects
None yet
Development

No branches or pull requests

1 participant