-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[RuntimeAsync] Use truncating sprintf to make resumption stub names #120698
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 CRT assert dialog issue in debug/checked builds when creating async resumption stub names. The change replaces sprintf_s
with _snprintf_s
using the _TRUNCATE
option to handle cases where method names are too long for the fixed-size buffer.
Key changes:
- Switches from
sprintf_s
to_snprintf_s
with_TRUNCATE
flag to prevent CRT assertion dialogs - Maintains the same buffer size and error checking logic
Tagging subscribers to this area: @mangod9 |
src/coreclr/vm/jitinterface.cpp
Outdated
char name[256]; | ||
int numWritten = sprintf_s(name, ARRAY_SIZE(name), "IL_STUB_AsyncResume_%s_%s", m_pMethodBeingCompiled->GetName(), optimizationTierName); | ||
int numWritten = _snprintf_s(name, ARRAY_SIZE(name), _TRUNCATE, "IL_STUB_AsyncResume_%s_%s", m_pMethodBeingCompiled->GetName(), optimizationTierName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the logic to make a long enough buffer instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed we wanted to cap how large the name may get. The names could end up arbitrary long and this is not a debug-only code.
Is there a purpose for resumption stub names in Release?
Can they all be just called "ResumptionStub"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a purpose for resumption stub names in Release?
Can they all be just called "ResumptionStub"?
Yeah, I think this should be debug-only. There is already a default name given to these stubs here:
runtime/src/coreclr/vm/ilstubcache.cpp
Line 141 in 56484c9
case DynamicMethodDesc::StubAsyncResume: return "IL_STUB_AsyncResume"; |
The extra info was just for diagnostic purposes.
sprintf_s
pops a crt assert dialog in checked/debug if the buffer is too short._snprintf_s
with_TRUNCATE
does not have such problem.We may see some pretty long names here.
An example that was triggering the assert in #119432 was:
System.Collections.Generic.IAsyncEnumerator<System.ValueTuple<Microsoft.CodeAnalysis.Project,System.Collections.Immutable.ImmutableArray<System.ValueTuple<Microsoft.CodeAnalysis.ISymbol,Microsoft.CodeAnalysis.FindSymbols.SymbolGroup>>>>.MoveNextAsync