You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-7726 Data.withUnsafe(Mutable)Bytes should use bindMemory(to:) instead of assumingMemoryBound(to:)
Issue Description:
Currently the implementation of _DataStorage's enumerateBytes method uses assumingMemoryBound(to:) in order to obtain a typed pointer to the underlying memory – however this can produce undefined behaviour if the underlying memory is bound to a type unrelated to UInt8.
Instead, we should probably use bindMemory(to:) in order to avoid this potential source of UB (at least until the API for enumerateBytes changes to work with a UnsafeRawBufferPointer instead of a UnsafeBufferPointer<UInt8>).
Additional Detail from JIRA
md5: bda013309a6dcfbc21532411d9cfdc6f
relates to:
Issue Description:
Currently the implementation of
_DataStorage
'senumerateBytes
method usesassumingMemoryBound(to:)
in order to obtain a typed pointer to the underlying memory – however this can produce undefined behaviour if the underlying memory is bound to a type unrelated toUInt8
.Instead, we should probably use
bindMemory(to:)
in order to avoid this potential source of UB (at least until the API forenumerateBytes
changes to work with aUnsafeRawBufferPointer
instead of aUnsafeBufferPointer<UInt8>
).See https://forums.swift.org/t/how-to-use-data-withunsafebytes-in-a-well-defined-manner/12811 for more context.
The text was updated successfully, but these errors were encountered: