Skip to content

Crash when switching back from the alt buffer #17709

@j4james

Description

@j4james

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:

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:

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.

Metadata

Metadata

Assignees

Labels

Area-OutputRelated to output processing (inserting text into buffer, retrieving buffer text, etc.)In-PRThis issue has a related PRIssue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsProduct-TerminalThe new Windows Terminal.Severity-CrashCrashes are real bad news.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions