Skip to content

[5.7][stdlib] Work around binary compatibility issues with String index validation fixes in 5.7 #58993

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

Conversation

lorentey
Copy link
Member

(Cherry picked from #58954)

  • Explanation: Swift 5.7 added stronger index validation for String, so some illegal cases that previously triggered inconsistently diagnosed out of bounds accesses now result in reliable runtime errors. Similarly, attempts at applying an index originally vended by a UTF-8 string on a UTF-16 string now result in a reliable runtime error.

    As is usually the case, adding new traps to the stdlib exposes some existing code that contains previously undiagnosed / unreliably diagnosed coding issues. This change allows invalid code inside binaries built with earlier versions of the stdlib to continue running with the 5.7 library by disabling some of the new traps based on the version of Swift the binary was built with.

    In the case of an index encoding mismatch, allow transcoding of string storage regardless of the direction of the mismatch. (Previously we only allowed transcoding a UTF-8 string to UTF-16.)

  • Scope: String in the Standard Library; binary compatibility.

  • Risk: Medium. While the change is relatively large, it merely loosens the Stdlib's preconditions, allowing entry points to succeed in more cases. The primary risk has to do with the introduction of the new bincompat checks, especially as they come with a new stdlib/runtime interface through SwiftShims additions.

  • Issue: rdar://93379333

  • Reviewer: @glessard

…lidation fixes in 5.7

Swift 5.7 added stronger index validation for `String`, so some illegal cases that previously triggered inconsistently diagnosed out of bounds accesses now result in reliable runtime errors. Similarly, attempts at applying an index originally vended by a UTF-8 string on a UTF-16 string now result in a reliable runtime error.

As is usually the case, new traps to the stdlib exposes code that contains previously undiagnosed / unreliably diagnosed coding issues.

Allow invalid code in binaries built with earlier versions of the stdlib to continue running with the 5.7 library by disabling some of the new traps based on the version of Swift the binary was built with.

In the case of an index encoding mismatch, allow transcoding of string storage regardless of the direction of the mismatch. (Previously we only allowed transcoding a UTF-8 string to UTF-16.)

rdar://93379333
(cherry picked from commit 50c2399)
@lorentey lorentey requested a review from a team as a code owner May 20, 2022 00:34
@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey merged commit 598fb53 into swiftlang:release/5.7 Jun 2, 2022
@lorentey lorentey deleted the string-bincompat-workarounds-5.7 branch June 2, 2022 18:48
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