Skip to content

Conversation

@MihaZupan
Copy link
Member

Fixes the issue discussed in #118083 (comment)

Alternatively we could make copies only in IsUnicodeCategoryOfSmallCharCount, but this seemed more likely to prevent us from introducing the same issue from a different caller elsewhere.

@MihaZupan MihaZupan added this to the 10.0.0 milestone Jul 26, 2025
@MihaZupan MihaZupan self-assigned this Jul 26, 2025
Copilot AI review requested due to automatic review settings July 26, 2025 19:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a multithreading issue in the Regex source generator where multiple threads could potentially modify the same character array concurrently. The fix involves making defensive copies of character arrays to prevent race conditions during the sorting operation.

  • Changes the EmitSearchValues method signature to accept ReadOnlySpan<char> instead of char[]
  • Creates a local copy of the span as an array before sorting to prevent concurrent modifications
  • Updates the caller to pass ReadOnlySpan<char> directly instead of pre-converting to array

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@MihaZupan MihaZupan enabled auto-merge (squash) July 26, 2025 20:24
@MihaZupan MihaZupan merged commit 655836e into dotnet:main Jul 27, 2025
87 of 89 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants