runtime: ExcecutionEngineException when using StringBuilder on long strings
Description
This issue was originally reported to Visual Studio (https://developercommunity.visualstudio.com/t/Prevent-using-precompiled-images-in-de/10363031) because it seems to only reproduce when turning off precompiled images under the debugger.
Reproduction Steps
- Create a simple dotnet 7 console application with the following code:
var count = 100000;
_ = string.Join(" ", Enumerable.Range(0, count).Select(_ => "Hello world!"));
-
In Visual Studio, turn on the option in Tools > Options > Debugging > General > “Prevent using precompiled images…”
-
Start debugging.
Expected behavior
The application runs to completion.
Actual behavior
Either an ArgumentOutOfRangeException or an ExecutionEngineException is thrown.
Regression?
No response
Known Workarounds
No response
Configuration
Using dotnet 7.0.5, and the latest dotnet 8 preview. Windows 11 x64
Other information
I think that it might be due to an overflow error while computing the length of the underlying span that is being used by the StringBuilder.
This repros in both dotnet 7, and dotnet 8 preview, though the location that the error is thrown from in dotnet 8 is different. I have heap dumps of the crashing processes in dotnet 7. I can make some for dotnet 8 if necessary as well.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (13 by maintainers)
Commits related to this issue
- Block tiering more broadly if the debugger disables optimizations In #88199 the debugger is overriding some jit flags, but has left other flags set that confuse the jit: both `TIER0` and `DEBUG_CODE`... — committed to AndyAyersMS/runtime by AndyAyersMS a year ago
- JIT: Don't set patchpoints in methods with CORINFO_DEBUG_CODE (#88227) In #88199 the debugger is overriding some jit flags, but has left other flags set that confuse the jit: both `TIER0` and `DEBUG... — committed to dotnet/runtime by AndyAyersMS a year ago
Right, there’s currently no way to test this config outside of debugging.
As I suspected
Either the jit interface should remove
TIER0
or the jit should ignore it ifDEBUG_CODE
is present.