Fix crash in fillNullTerminatedWideStringBuffer()#304
Open
broken-circle wants to merge 1 commit into
Open
Conversation
The function passed a typed-throwing closure to `withUnsafeTemporaryAllocation()`, whose closure parameter is `rethrows`. Bridging the typed throw into `rethrows` miscompiles under release optimization on the Swift 6.2.x Windows toolchain and crashes; debug builds and nightly-main are unaffected. Restructure so the allocation closure no longer throws. Instead, it returns a result enum, and the enclosing loop throws or grows the buffer accordingly. This drops the typed-throws-into-`rethrows` bridge, which in turn drops the `#if swift(>=6.3)` workaround guarding the same path and allows `body` to be non-throwing, since no caller throws from it. Also remove `assert()`; the package avoids its use everwhere. Behavior is otherwise unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function passed a typed-throwing closure to
withUnsafeTemporaryAllocation(of:capacity:_:), which isrethrows. Bridging the typed throw intorethrowscrashes under release optimization on the Swift 6.2.x Windows toolchain (debug builds andnightly-mainare unaffected).This PR restructures it so the allocation closure no longer throws. Instead, it returns a result enum, and the enclosing loop throws or grows the buffer accordingly. This drops the typed-throws-into-
rethrowsbridge, which in turn drops the#if swift(>=6.3)workaround guarding the same path and allowsbodyto be non-throwing, since no caller throws from it.The original implementation used an
assert(); this was the only use in the package, and I removed it based on a review comment on #280 explaining that Subprocess tries not to useassert().Found this when running CI for #261.
Windows (6.2 - windows-2022)crashed, while all other CI includingWindows (nightly-main - windows-2022)passed.On
mainthis function is reached only through paths that run without crashing in release CI. #261 adds a new caller,currentWorkingDirectory(), invoked from the spawn path inConfiguration.run(), which is where the crash occurs.