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-14663] Array.withContiguousStorageIfAvailable traps #57014

Closed
lorentey opened this issue May 26, 2021 · 6 comments
Closed

[SR-14663] Array.withContiguousStorageIfAvailable traps #57014

lorentey opened this issue May 26, 2021 · 6 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@lorentey
Copy link
Member

Previous ID SR-14663
Radar rdar://problem/78640103
Original Reporter @lorentey
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.4

Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Bug
Assignee @lorentey
Priority Medium

md5: 0466e0c80347cee4f381b18dcaa94f98

Issue Description:

As discovered by @mdznr in apple/swift-collections#27 verbatim-bridged Arrays trap on withContiguousStorageIfAvailable.

let array = NSArray(array: [NSObject()]) as! [NSObject]
array.withContiguousStorageIfAvailable { _ in } // traps

withContiguousStorageIfAvailable must not ever trap.

@lorentey
Copy link
Member Author

This seems to have been broken since Swift 5.1 (that shipped in Xcode 11 as part of macOS 10.15, iOS 13, watchOS 6, and tvOS 13).

It may be worth making sure the fix deploys back to these earlier OS releases (if possible). As it stands, it is not safe to call wCSIA on Arrays.

@lorentey
Copy link
Member Author

The same issue applies to the `withUnsafeBufferPointer` method, and probably all other methods that provide direct access to the array's underlying storage.

@typesanitizer
Copy link

@swift-ci create

@lorentey
Copy link
Member Author

This was resolved by #37914 on the main branch. The fix is expected to deploy back to earlier releases, as long as the binary gets recompiled with a stdlib that contains this fix – although unfortunately this isn't 100% guaranteed.

@lorentey
Copy link
Member Author

I'll try to cherry-pick this to the 5.5 release branch too.

@tonyarnold
Copy link
Contributor

Did this fix make it into the 5.5 release? I'm seeing an almost identical fatal error when calling difference(from: …) on an NSArray associated with an Objective-C instance:

Swift/ArrayBuffer.swift:319: Fatal error: unsupported

Edit: on further testing, the same code works fine on macOS 12.0b9, so perhaps this is an issue of back deployment. I'll see if I can create a minimal reproduction and file a new issue - sorry for the noise!

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

3 participants