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-9869] Passing an empty UnsafeBufferPointer with null pointer crashes String(decoding:as:) #52275

Closed
akyrtzi opened this issue Feb 6, 2019 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@akyrtzi
Copy link
Member

akyrtzi commented Feb 6, 2019

Previous ID SR-9869
Radar rdar://problem/47864610
Original Reporter @akyrtzi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee @milseman
Priority Medium

md5: baa7209efea17d6f0d3d222b8d000f65

Issue Description:

The following code:

let emptyBuffer: UnsafeBufferPointer<UInt8> = .init(start: nil, count: 0)
_ = String(decoding: emptyBuffer, as: UTF8.self)

Crashes when using a StdLib as built from CI (tested on master, 2e252e1)

Output:

./build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift /tmp/buffer-str.swift 
Fatal error: _unsafelyUnwrappedUnchecked of nil optional: file /Users/argiris/proj/swift/master/workspace/swift/stdlib/public/core/Optional.swift, line 262
Current stack trace:
0    libswiftCore.dylib                 0x00000001138168a0 _swift_stdlib_reportFatalErrorInFile + 116
1    libswiftCore.dylib                 0x000000011372fc00 specialized closure #&#8203;1 in closure #&#8203;1 in closure #&#8203;1 in _fatalErrorMessage(_:_:file:line:flags:) + 306
2    libswiftCore.dylib                 0x00000001136e82c0 specialized closure #&#8203;1 in closure #&#8203;1 in _fatalErrorMessage(_:_:file:line:flags:) + 113
3    libswiftCore.dylib                 0x00000001136e8680 specialized closure #&#8203;1 in _fatalErrorMessage(_:_:file:line:flags:) + 99
4    libswiftCore.dylib                 0x00000001136e8a20 specialized _fatalErrorMessage(_:_:file:line:flags:) + 561
5    libswiftCore.dylib                 0x00000001134d4920 protocol witness for _HasContiguousBytes.withUnsafeBytes<A>(_:) in conformance UnsafeBufferPointer<A> + 168
6    libswiftCore.dylib                 0x0000000113630350 String.init<A, B>(decoding:as:) + 463
@belkadan
Copy link
Contributor

belkadan commented Feb 6, 2019

cc @milseman

@milseman
Copy link
Mannequin

milseman mannequin commented Feb 6, 2019

Good news is that this seems unique to UBP, that is Array etc don't exhibit this behavior, even though we grab an underlying UBP. I'll try to get a fix in for the next beta here.

@milseman
Copy link
Mannequin

milseman mannequin commented Feb 6, 2019

#22417

@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

2 participants