-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
Windows Terminal version
Commit edfa3ea
Windows build number
10.0.19045.4651
Other Software
No response
Steps to reproduce
It's not easy to reproduce, but I think all you really need to trigger the crash is to switch to the alt buffer with printf "\e[?1049h", and then switch back to the main buffer with printf "\e[?1049l".
This is in Windows Terminal using a build that includes the new VT passthrough (PR #17510).
Expected Behavior
The terminal should not crash.
Actual Behavior
I got an access violation accessing the screenInfo parameter in the WriteCharsVT function here:
Line 353 in 0199ca3
| if (WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN)) |
What happens is that we first pass the \e[?1049l sequence through to conhost in the stateMachine.ProcessString call a couple of lines above. That ends up calling SCREEN_INFORMATION::UseMainScreenBuffer, which calls s_RemoveScreenBuffer(psiAlt), which deletes the active screenInfo instance here:
terminal/src/host/screenInfo.cpp
Line 231 in 0199ca3
| delete pScreenInfo; |
That's the same screenInfo instance that was passed to our WriteCharsVT function, so when we later try to reference that, we're referencing a deleted object. Sometimes we get lucky and nothing bad happens, but sometimes it will crash.
I think maybe all we need to do to prevent the crash is to save the screenInfo.OutputMode at the start of the function, and then use that saved value instead of trying to look it up via the screenInfo object.