Skip to content

SetConsoleScreenBufferSize(something < viewport) crashes ConPTY host #3907

Closed

Description

  1. A pseudoconsole host is a headless console
  2. Headless consoles have no minimum size
  3. SetConsoleScreenBufferSize(new) checks to make sure the following are true:
    • new is within minimum size
    • new is within current viewport size
  4. SetConsoleScreenBufferSize only does this check if a console is headful (i.e. not headless)

if (!ServiceLocator::LocateGlobals().IsHeadless())
{
COORD const coordMin = screenInfo.GetMinWindowSizeInCharacters();
// clang-format off
// Make sure requested screen buffer size isn't smaller than the window.
RETURN_HR_IF(E_INVALIDARG, (size.X < screenInfo.GetViewport().Width() ||
size.Y < screenInfo.GetViewport().Height() ||
size.Y < coordMin.Y ||
size.X < coordMin.X));
// clang-format on
}

  1. When we're attached to a conpty, it happily resizes the buffer to be smaller than the viewport.
  2. The next time the whole screen is invalidated (or whenever luck strikes, really), the renderer tries to render the whole viewport, which is now outside the bounds of the buffer.

This part of the check should probably be moved outside of the "are we headful" block;

RETURN_HR_IF(E_INVALIDARG, (size.X < screenInfo.GetViewport().Width() ||
size.Y < screenInfo.GetViewport().Height() ||

Trivial repro code:

#include <Windows.h>
int main(int argc, char *argv[])
{
	HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleScreenBufferSize(hStdOut, {10,10});
	return 0;
}

This purchases a nice plot of land overlooking a cemetery for both WSL interop and Windows Terminal. 😄

Activity

  1. added
    Product-ConptyFor console issues specifically related to conpty
    Area-ServerDown in the muck of API call servicing, interprocess communication, eventing, etc.
    Issue-BugIt either shouldn't be doing this or needs an investigation.
    on Dec 11, 2019
  2. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Dec 11, 2019
  3. changed the title [-]SetConsoleScreenBufferSize(something < viewport) crashes contpy host[/-] [+]SetConsoleScreenBufferSize(something < viewport) crashes PTY host[/+] on Dec 11, 2019
  4. changed the title [-]SetConsoleScreenBufferSize(something < viewport) crashes PTY host[/-] [+]SetConsoleScreenBufferSize(something < viewport) crashes ConPTY host[/+] on Dec 11, 2019
  5. zadjii-msft commented on Dec 12, 2019

    @zadjii-msft
    Member
     RETURN_HR_IF(E_INVALIDARG, (size.X < screenInfo.GetViewport().Width() || 
                                 size.Y < screenInfo.GetViewport().Height())); 
    
     if (!ServiceLocator::LocateGlobals().IsHeadless()) 
     { 
         COORD const coordMin = screenInfo.GetMinWindowSizeInCharacters(); 
         // clang-format off 
         // Make sure requested screen buffer size isn't smaller than the window. 
         RETURN_HR_IF(E_INVALIDARG, (size.Y < coordMin.Y || 
                                     size.X < coordMin.X)); 
         // clang-format on 
     }
    
  6. ghost added
    In-PRThis issue has a related PR
    on Dec 19, 2019
  7. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Dec 31, 2019
  8. ghost removed
    In-PRThis issue has a related PR
    on Dec 31, 2019
  9. ghost added
    Resolution-Fix-CommittedFix is checked in, but it might be 3-4 weeks until a release.
    on Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-ServerDown in the muck of API call servicing, interprocess communication, eventing, etc.Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsProduct-ConptyFor console issues specifically related to conptyResolution-Fix-CommittedFix is checked in, but it might be 3-4 weeks until a release.Severity-CrashCrashes are real bad news.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions