Skip to content

[5.7][stdlib] Switch to using unchecked buffer subscript in low-level Unicode helpers #59901

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

lorentey
Copy link
Member

@lorentey lorentey commented Jul 6, 2022

(cherry picked from #59899)

Description: This fixes a minor binary compatibility issue by allowing invalid String indices to be passed to some String operations without a runtime trap, as long as the binary was built with Swift 5.6 or earlier. This allows broken code to keep "working" as it did in earlier Standard Library releases, while still allowing us to catch & report the issue for binaries compiled with the new SDK.
Risk: Low. This eliminates some low-level checks that were already supposed to have been done by the time this code is called. The primary risk is that in some cases these checks may be our last safety net against out-of-bounds access.
Review by: @glessard & @Azoy
Testing: Regular regression testing, plus manual bincompat verification.
Original PR: #59899
Issue: rdar://93707276

…ode helpers

We expect indices to be already validated by the time these are
called, and UBP’s debug-mode checks are compiled into opaque parts
of the stdlib.

(The big exception is that Swift <5.7 used to not do proper index
validation and allowed out-of-bounds accesses. We emulate this
behavior for code that was compiled with such a release, and it turns
out that these UnsafeBufferPointer checks are interfering with the
intended (undefined) behavior.)

rdar://93707276
(cherry picked from commit 64a57e3)
@lorentey lorentey requested a review from a team as a code owner July 6, 2022 02:44
@lorentey
Copy link
Member Author

lorentey commented Jul 6, 2022

@swift-ci test

@lorentey lorentey changed the title [stdlib] Switch to using unchecked buffer subscript in low-level Unicode helpers [5.7][stdlib] Switch to using unchecked buffer subscript in low-level Unicode helpers Jul 6, 2022
@lorentey lorentey merged commit 83d77f7 into swiftlang:release/5.7 Jul 6, 2022
@lorentey lorentey deleted the unchecked-buffer-access-inside-strings-5.7 branch July 6, 2022 21:07
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.

2 participants