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-4462] Data.replaceSubrange can lead to empty Data #4534

Closed
swift-ci opened this issue Apr 1, 2017 · 2 comments
Closed

[SR-4462] Data.replaceSubrange can lead to empty Data #4534

swift-ci opened this issue Apr 1, 2017 · 2 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

@swift-ci swift-ci commented Apr 1, 2017

Previous ID SR-4462
Radar rdar://problem/31404279
Original Reporter SimonSeyer (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 8.3 (8E162)
Swift 3.1

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, 3.1Regression
Assignee @phausler
Priority Medium

md5: 5d2fb4c51b6ac4475003ac5b9e037656

Issue Description:

I haven't been able to pinpoint the problem exactly so far but in some cases Data.replaceSubrange can lead to an empty Data object.

var data = Data(bytes: [0x01, 0x02])

var dataI = data
dataI.replaceSubrange(0..<1, with: Data()) // Works as expected: [0x02]

var dataII = Data(base64Encoded: data.base64EncodedString())!
dataII.replaceSubrange(0..<1, with: Data()) // BUG: result is empty, 0 bytes

var dataIII = Data(base64Encoded: data.base64EncodedString())!
dataIII.replaceSubrange(0..<1, with: []) // Works again: [0x02]

In the code above, replacing the first byte with empty Data (aka removing it) only works in case I and III. The code only varies in how the modified Data object and the replacing data are constructed.

In our production code the original data object got constructed by using the empty initializer and by appending data constructed with init(bytes: UnsafeRawPointer, count: Int) by calling append(_ other: Data). So there seems to be some variation in how this bug is triggered.

The code above (case II) worked with Swift 3.0 / Xcode 8.2.1. We worked around the problem now by using the code in case III above.

@belkadan
Copy link

@belkadan belkadan commented Apr 3, 2017

@swift-ci create

@phausler
Copy link
Member

@phausler phausler commented Apr 3, 2017

Fixed for swift-corelibs-foundation in #929
Fixed for Foundation overlay in apple/swift#8510

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 6, 2022
This issue was closed.
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

3 participants