Prevent separator buffer overruns in string.Join - #134529
Merged
tannergooding merged 1 commit intoSep 23, 2026
Merged
tannergooding merged 1 commit into
tannergooding merged 1 commit into
Conversation
Use a bounded, advancing destination span for value and separator copies while preserving the defensive-copy retry for concurrent input mutation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
All reviewed changes are covered by passing regression tests with no unresolved blocking issues.
Review effort: Lite
Findings: None
What changed in this PR
Fixes a concurrent-mutation buffer overrun in String.Join by bounding separator and value writes.
Changes:
- Uses bounded destination spans with safe copy retries.
- Adds regression tests for varied separator lengths and mutation positions.
| File | Description |
|---|---|
src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs |
Bounds result-buffer writes and preserves defensive-copy retry behavior. |
src/libraries/Common/tests/Tests/System/StringTests.cs |
Adds concurrent-mutation regression coverage. |
EgorBo
reviewed
Sep 23, 2026
EgorBo
approved these changes
Sep 23, 2026
tannergooding
enabled auto-merge (squash)
September 23, 2026 19:30
MihaZupan
approved these changes
Sep 23, 2026
Member
Author
|
/ba-g unrelated failure |
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.
String.JoinCorealready anticipates concurrent input mutation and retries with a defensive copy when the copies do not match the allocated length. However, it only checked capacity for values: a value could consume the remaining space, after which the unchecked separator write could overrun the result buffer.Use a destination span bounded by the allocated string's length for both value and separator writes, advancing it after each successful copy. Preserve the single-character separator fast path and the existing defensive-copy retry, including when a copy fails after exhausting the destination.
Add an outer-loop concurrency theory covering separator lengths 1, 2, and 4000 with mutation at two input positions. The test triggered a heap-integrity assertion on the unmodified checked runtime. With the fix, all six cases pass; the full StringTests run had 2,195 passes and seven existing platform skips. After the final range-syntax edit, the checked CoreLib rebuild and all 73 Join tests passed.
Local Release BenchmarkDotNet comparisons showed unchanged allocations. Throughput measurements were noisy and inconclusive; this does not establish performance neutrality.
Resolves #134515
Note
This PR description was drafted by GitHub Copilot.