Skip to content

Fix crashes in Unsafe[Raw]BufferPointer with nil baseAddress. #22521

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

Merged
merged 1 commit into from
Feb 12, 2019
Merged

Fix crashes in Unsafe[Raw]BufferPointer with nil baseAddress. #22521

merged 1 commit into from
Feb 12, 2019

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Feb 11, 2019

This fix updates various initializers to handle incoming empty buffers
that happen to have a nil base. They should simply create another
buffer with nil base rather than crashing!

It is valid for an Unsafe[Raw]BufferPointer can have a nil base
address. This allows round-tripping with C code that takes a
pointer/length pair and uses 0 as the pointer value.

The original design wrongly assumed that we would use a sentinel value
for empty buffers and was never updated for or tested with the current
design.

Fixes rdar://problem/47946984 Regression in Foundation.Data's
UnsafeBufferPointer constructor.

This fix updates various initializers to handle incoming empty buffers
that happen to have a nil base. They should simply create another
buffer with nil base rather than crashing!

It is valid for an Unsafe[Raw]BufferPointer can have a nil base
address. This allows round-tripping with C code that takes a
pointer/length pair and uses `0` as the pointer value.

The original design wrongly assumed that we would use a sentinel value
for empty buffers and was never updated for or tested with the current
design.

Fixes <rdar://problem/47946984> Regression in Foundation.Data's
UnsafeBufferPointer constructor.
@atrick
Copy link
Contributor Author

atrick commented Feb 11, 2019

@swift-ci test.

@atrick
Copy link
Contributor Author

atrick commented Feb 11, 2019

@swift-ci test source compatibility.

@atrick atrick requested a review from airspeedswift February 11, 2019 21:48
@atrick
Copy link
Contributor Author

atrick commented Feb 11, 2019

@airspeedswift can you review this for 5.0?

@atrick
Copy link
Contributor Author

atrick commented Feb 11, 2019

@itaiferber please review.

Copy link
Contributor

@itaiferber itaiferber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@phausler
Copy link
Contributor

Thanks for addressing this! The changes look good to me.

@atrick
Copy link
Contributor Author

atrick commented Feb 11, 2019

@itaiferber you might still want to add a test on the Foundation side. I just wanted to get this fix in quickly.

@itaiferber
Copy link
Contributor

itaiferber commented Feb 11, 2019

@atrick Yep, once this is in I'll add a unit test on the Foundation side (filed 47978737)

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 28a529c

Copy link
Contributor

@jakepetroules jakepetroules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@atrick
Copy link
Contributor Author

atrick commented Feb 11, 2019

@swift-ci smoke test OSX platform.

@atrick
Copy link
Contributor Author

atrick commented Feb 11, 2019

@swift-ci smoke test OS X platform.

@atrick
Copy link
Contributor Author

atrick commented Feb 12, 2019

Been trying to get this through PR testing all afternoon. It appears to be blocked on #22534

@atrick
Copy link
Contributor Author

atrick commented Feb 12, 2019

@swift-ci smoke test OS X platform

@atrick atrick merged commit 638c3ea into swiftlang:master Feb 12, 2019
@atrick atrick deleted the fix-nil-buffer branch February 22, 2019 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants