-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
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.
@swift-ci test. |
@swift-ci test source compatibility. |
@airspeedswift can you review this for 5.0? |
@itaiferber please review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for addressing this! The changes look good to me. |
@itaiferber you might still want to add a test on the Foundation side. I just wanted to get this fix in quickly. |
@atrick Yep, once this is in I'll add a unit test on the Foundation side (filed 47978737) |
Build failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@swift-ci smoke test OSX platform. |
@swift-ci smoke test OS X platform. |
Been trying to get this through PR testing all afternoon. It appears to be blocked on #22534 |
@swift-ci smoke test OS X platform |
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.