SetConsoleScreenBufferSize(something < viewport) crashes ConPTY host #5494

Closed
opened 2026-01-31 00:14:40 +00:00 by claunia · 2 comments
Owner

Originally created by @DHowett-MSFT on GitHub (Dec 11, 2019).

Originally assigned to: @zadjii-msft on GitHub.

  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)

381b11521a/src/host/getset.cpp (L509-L519)

  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;
381b11521a/src/host/getset.cpp (L514-L515)

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. 😄

Originally created by @DHowett-MSFT on GitHub (Dec 11, 2019). Originally assigned to: @zadjii-msft on GitHub. 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) https://github.com/microsoft/terminal/blob/381b11521aaaa9a84eea2a308e65d4c5097cc57d/src/host/getset.cpp#L509-L519 5. When we're attached to a conpty, it _happily_ resizes the buffer to be smaller than the viewport. 6. 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; https://github.com/microsoft/terminal/blob/381b11521aaaa9a84eea2a308e65d4c5097cc57d/src/host/getset.cpp#L514-L515 Trivial repro code: ```cpp #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. :smile:
Author
Owner

@zadjii-msft commented on GitHub (Dec 12, 2019):

 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 
 }

@zadjii-msft commented on GitHub (Dec 12, 2019): ```c++ 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 } ```
Author
Owner

@ghost commented on GitHub (Jan 14, 2020):

:tada:This issue was addressed in #4021, which has now been successfully released as Windows Terminal Preview v0.8.10091.0.🎉

Handy links:

@ghost commented on GitHub (Jan 14, 2020): :tada:This issue was addressed in #4021, which has now been successfully released as `Windows Terminal Preview v0.8.10091.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.8.10091.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5494