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-14420] NSData.bytes is very hard to hold safely, especially on non-Apple platforms #3229

Open
Lukasa opened this issue Mar 29, 2021 · 1 comment

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Mar 29, 2021

Previous ID SR-14420
Radar rdar://problem/76010121
Original Reporter @Lukasa
Type Bug
Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: b40c2cee60a72f9c6e5ee6f3a3ac56b7

Issue Description:

NSData.bytes is a straightforward translation of the Objective-C [NSData bytes] property accessor from Objective-C. The method returns an interior pointer to the buffer of an NSData object.

Recent improvements to the copy propagation optimization pass have made this property very dangerous on non-Apple platforms, including breaking [swift-corelibs-foundation| #2994] in recent top-of-tree Swift versions.

To use this property safely will almost invariably require the use of withExtendedLifetime to keep the parent NSData object alive. We should consider deprecating this in favour of Data.withUnsafeBytes, or providing a diagnostic for using NSData.bytes as the last usage point, or at the very least making it clear that this Objective-C-ism is potentially much more dangerous than it looks.

@typesanitizer
Copy link

@swift-ci create

@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