-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
Hi
I'm currently experiencing a crash in one of my applications which uses the hostfxr environment to load .NET Assemblies. The application is generally a GUI application, however we use the CONSOLE subsystem to have support for a command line interface. When run from the regular explorer, the application detects this and calls FreeConsole() to hide the console window.
This works fine for the most part, however we noticed that FreeConsole() apparently leaves the stdout, stderr and stdin handles in an invalid state which later on causes a crash here when the JIT tries to duplicate the stdout handle. The code there seems to do some checks already but doesn't seem to catch this problem.
Reproduction Steps
The latest nightly release of ImHex triggers this issue at launch on Windows 10 sometimes. It's not consistent but it happens often.
It can be downloaded from https://imhex.download/#nightly
Alternatively, a simple application which uses the CONSOLE subsystem, calls FreeConsole() and then loads an Assembly through the hostfxr functions should reproduce the issue on Windows 10.
Expected behavior
stdout should simply not be used in this case instead of causing a crash
Actual behavior
The call to _dup() at
runtime/src/coreclr/jit/ee_il_dll.cpp
Line 92 in de0ab15
| int jitstdoutFd = _dup(_fileno(procstdout())); |
Regression?
No response
Known Workarounds
Interestingly enough, this issue seems to only affect Windows 10 (and potentially even older versions of Windows). It does not happen on Windows 11.
Configuration
- .NET 7.0.400
- Windows 10
- x64
- It's specific to Windows 10 (and potentially before), not Windows 11
Other information
- My application:
https://github.com/WerWolv/ImHex - The code that calls
FreeConsole(): https://github.com/WerWolv/ImHex/blob/master/main/source/window/win_window.cpp#L238-L251 - The code that initializes the .NET runtime and loads an Assembly: https://github.com/WerWolv/ImHex/blob/master/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp#L156
- Stacktrace:
