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-9622] Data.withUnsafeMutableBytes crash on empty data build with suffix, prefix, dropFirst or dropLast functions #3561

Open
swift-ci opened this issue Jan 8, 2019 · 1 comment

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jan 8, 2019

Previous ID SR-9622
Radar None
Original Reporter oleksii.lyzenko (JIRA User)
Type Bug
Environment

Xcode 10.1 (10B61)

Swift 4.2

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 248cd2ff2bf9232cd0e28d866bb7a58d

Issue Description:

Code compiles, but always throws an exception EXC_BAD_INSTRUCTION

let initialData = Data()
var invalidChunk = initialData.dropLast(1) // or prefix(len), suffix(len), dropFirst(k), dropLast(k)

print(invalidChunk) // 0 bytes, looks like valid Data

let finalMessage =
    invalidChunk.withUnsafeMutableBytes { (rawTag: UnsafeMutablePointer<UInt8>) -> Data in // EXC_BAD_INSTRUCTION
        return Data()
    }

print(finalMessage)

Other initialization examples:

let initialData = Data(repeating: 1, count: 2)
var invalidChunk = initialData.prefix(0) // or suffix(0)
let initialData = Data(repeating: 1, count: 2)
var invalidChunk = initialData.dropFirst(2) // or dropLast(k), k >= 2

Backtrace:

* thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

  * frame #&#8203;0: 0x000000010005d569 RawDataTest`Foundation._DataStorage.withUnsafeMutableBytes<A>(in: Swift.Range<Swift.Int>, apply: (Swift.UnsafeMutableRawBufferPointer) throws -> A) throws -> A + 1113

    frame #&#8203;1: 0x000000010006a11e RawDataTest`Foundation.Data.withUnsafeMutableBytes<A, B>((Swift.UnsafeMutablePointer<B>) throws -> A) throws -> A + 222

    frame #&#8203;2: 0x000000010000263b RawDataTest`main at main.swift:19

    frame #&#8203;3: 0x00007fff69a9608d libdyld.dylib`start + 1
@belkadan
Copy link

belkadan commented Jan 8, 2019

Seems to be fixed in master, but probably worth adding tests for! cc @phausler

@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