Skip to content

[6.3 🍒] Switch to lossy UTF8 decoding for dependency scanner diagnostic result strings#2081

Open
artemcm wants to merge 1 commit intoswiftlang:release/6.3from
artemcm:63FixForceUnwrapOnInvalidUTF8
Open

[6.3 🍒] Switch to lossy UTF8 decoding for dependency scanner diagnostic result strings#2081
artemcm wants to merge 1 commit intoswiftlang:release/6.3from
artemcm:63FixForceUnwrapOnInvalidUTF8

Conversation

@artemcm
Copy link
Contributor

@artemcm artemcm commented Feb 11, 2026

Cherry-pick of #2080

  • Explanation
    The toSwiftString code currently force-unwraps a String initializer which attempts to decode the input buffer as valid UTF-8. We have seen a crash on this force-unwrap.
    This change switches toSwiftString to use the Swift standard library's String(decoding:,as:) instead of Foundation's String(data:,encoding:). The former returns a non-optional value which replaces non-UTF-8 characters with a Unicode replacement character, instead of failing and returning nil.
    This will not only resolve the crash, but also result in us emitting these potentially-corrupted strings for the user to see.

  • Resolves: rdar://157486211

  • Main branch PR: Switch to lossy UTF8 decoding for dependency scanner diagnostic result strings #2080

  • Risk: Low, this change removes a force-unwrap which was previously hit when encountering non-UTF8 strings in the dependency scanner output. It replaces it with a lossy conversion method which will not crash when encountering such invalid strings.

  • Reviewed By: TBD

  • Testing: Tests added to the driver test suite to validate the new logic results in the driver no longer crashing on invalid UTF8 dependency scanner output.

…t strings

The 'toSwiftString' code currently force-unwraps a 'String' initializer which attempts to decode the input buffer as valid UTF-8. We have seen a crash on this force-unwrap.

This change switches 'toSwiftString' to use the Swift standard library's 'String(decoding:,as:)' instead of Foundation's 'String(data:,encoding:)'. The former returns a non-optional value which replaces non-UTF-8 characters with a Unicode replacement character, instead of failing and returning 'nil'.

This will not only resolve the crash, but also result in us emitting these potentially-corrupted strings for the user to see.

Resolves rdar://157486211
@artemcm
Copy link
Contributor Author

artemcm commented Feb 11, 2026

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants