-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.DotNet.ApiCompat failing with RegexMatchTimeoutException in #81543
Comments
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue Details
Build InformationBuild: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=157087 Error MessageFill the error message using known issues guidance. {
"ErrorMessage": "Microsoft.DotNet.ApiCompat.RegexStringTransformer.Transform",
"BuildRetry": true,
"ErrorPattern": "",
"ExcludeConsoleLog": false
}
|
Tagging subscribers to this area: @dotnet/area-infrastructure-libraries Issue Details
Build InformationBuild: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=157087 Error MessageFill the error message using known issues guidance. {
"ErrorMessage": "Microsoft.DotNet.ApiCompat.RegexStringTransformer.Transform",
"BuildRetry": true,
"ErrorPattern": "",
"ExcludeConsoleLog": false
}
|
That's interesting. I would never have assumed that super simple patterns like the ones that APICompat uses could result in a timeout exception. The timeout is hardcoded to two seconds: https://github.com/dotnet/sdk/blob/80c0e6412ce0b5d56298c020e500f5a267fab1a1/src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RegexStringTransformer.cs#L16 The regex is just a replace that transforms an assembly path to a relative path with the help of capture groups: runtime/eng/resolveContract.targets Lines 79 to 86 in ddba2aa
I see that this happened on a osx-arm64 machine. Maybe that machine was overloaded and hence the operation timed out? We can definitely increase the timeout to 5 seconds but the overall APICompat tool invocation shouldn't take that long. |
Probably. The API compat tool is not running in security sensitive environment. I think it would be fine to run the regex without any timeout in API compat tool. We do not have similar timeouts in the other tools and compilers either. For example, you can make Roslyn to take forever on bad input. We do not protect against that. |
I imagine the backtracking here is just referring to NFA backtracking, so removing the timeout shouldn't result in pathological behavior or anything. |
Are these the patterns it's using? runtime/eng/resolveContract.targets Lines 58 to 59 in 1145e01
While they might be "super simple", they also contain multiple loops written in a way where they can't be automatically made atomic by the implementation and thus potentially have a non-trivial amount of backtracking and could be e.g. O(N^3) in the length of the input. Some simple changes would likely eliminate that backtracking. For example, the You could also change the tool to specify the RegexOptions.NonBacktracking option introduced in .NET 7. That guarantees linear time in the length of the input. You're restricted from doing certain advanced things in the pattern, but these patterns don't use those things (e.g. backreferences). And as Jan says, regardless you can raise or entirely remove the timeout (which will also be much less relevant with NonBacktracking). |
Fixes dotnet/runtime#81543 As discussed in dotnet/runtime, a regex timeout isn't necessary as the tool currently doesn't run in a security sensitive environment in our core stack repositories and customers aren't expected to be using this functionality in such an environment either. When ApiCompat upgrades and targets .NET 7+, we should also leverage the `RegexOptions.NonBacktracking` mode.
Build Information
Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=157087
Build error leg or test failing: Build / Libraries Build osx arm64 Debug / Restore and Build Product
Pull request: #81510
Error Message
Fill the error message using known issues guidance.
Report
Summary
The text was updated successfully, but these errors were encountered: