You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Libs: (bug) string.Join assumes the input is immutable #134515
I don't think this is a security issue as it involves a data race + the API doesn't give such guarantees, but it looks like we should make it more durable?
string.Join(string separator, string?[] values) (and the other overloads that reach JoinCore) makes two passes. The first sums the lengths and allocates the result. The second copies. The second pass is meant to survive concurrent mutation of values (the code comment says "We range check again to avoid buffer overflows if this happens"). It re-checks each value's length against the remaining space, but then writes the separator through Unsafe.Add with no check. If another thread swaps an element from null or short to a longer string between the passes, the separator is written past the end of the newly allocated string, corrupting the GC heap. The final "copied the wrong amount, retry with a defensive copy" fallback runs only after the overflow. Only ordinary safe APIs are involved.
Seems to have been caused by dotnet/coreclr#7942, between .NET Core 1.1 and 2.0. Before that, String.Join(String separator, String[] value, int startIndex, int count) used UnSafeCharBuffer.AppendString(string) for both separators and array elements, and that method threw IndexOutOfRangeException if the buffer filled up too early.
Agree: not a security issue. Mutating an input while an API is interpreting it is clearly operating outside the boundaries of what any API would ever reasonably be expected to support without explicit documentation to the contrary.
Whether you want to make a behavioral change to be more robust in this scenario is entirely up to you.
Activity
dotnet-policy-service commentedon Sep 23, 2026
Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.
KalleOlaviNiemitalo commentedon Sep 23, 2026
Seems to have been caused by dotnet/coreclr#7942, between .NET Core 1.1 and 2.0. Before that, String.Join(String separator, String[] value, int startIndex, int count) used UnSafeCharBuffer.AppendString(string) for both separators and array elements, and that method threw IndexOutOfRangeException if the buffer filled up too early.
GrabYourPitchforks commentedon Sep 23, 2026
Agree: not a security issue. Mutating an input while an API is interpreting it is clearly operating outside the boundaries of what any API would ever reasonably be expected to support without explicit documentation to the contrary.
Whether you want to make a behavioral change to be more robust in this scenario is entirely up to you.
Prevent separator buffer overruns in string.Join (#134529)