v2 conhost crash with SetConsoleScreenBufferInfoEx calls #377

Closed
opened 2026-01-30 21:50:18 +00:00 by claunia · 3 comments
Owner

Originally created by @rprichard on GitHub (Sep 17, 2018).

Originally assigned to: @miniksa on GitHub.

  • Your Windows build number: [Version 10.0.17760.1]

What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)

Using SetConsoleScreenBufferInfoEx to make the console buffer and window smaller, simultaneously, can crash the v2 conhost with a recent Insiders build.

Steps:

  1. Open a cmd/powershell console window.
  2. Open the console properties and uncheck the "Layout > Wrap text output on resize" option.
  3. Run the test program I included.
  4. The console window disappears.

What's wrong / what should be happening instead:

SetConsoleScreenBufferInfoEx shouldn't crash. The text Hello? should appear, and the console should return control to cmd/powershell.

Aside 1: I don't think this affects winpty at all.
Aside 2: SetConsoleScreenBufferInfoEx seems to handle srWindow differently than both SetConsoleWindowInfo and GetConsoleScreenBufferInfoEx. It tends to set the window size to 1 less width/height than the requested size, so a pair of calls to GetConsoleScreenBufferInfoEx and SetConsoleScreenBufferInfoEx shrinks the console window.

Test program

#include <windows.h>
#include <stdio.h>

int main(int argc, char *argv[]) {

    HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFOEX info = { sizeof(info) };
    GetConsoleScreenBufferInfoEx(conout, &info);

    info.dwSize.X = 120;
    info.dwSize.Y = 5000;
    info.srWindow.Left = info.srWindow.Top = 0;
    info.srWindow.Right = 121;
    info.srWindow.Bottom = 26;
    SetConsoleScreenBufferInfoEx(conout, &info);

    SetConsoleCursorPosition(conout, COORD { 0, 4000 });

    info.dwSize.X = 80;
    info.dwSize.Y = 20;
    info.srWindow.Right = 41;
    info.srWindow.Bottom = 11;
    SetConsoleScreenBufferInfoEx(conout, &info);

    printf("Hello?\n");

    return 0;
}
Originally created by @rprichard on GitHub (Sep 17, 2018). Originally assigned to: @miniksa on GitHub. * Your Windows build number: [Version 10.0.17760.1] ## What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots) Using `SetConsoleScreenBufferInfoEx` to make the console buffer and window smaller, simultaneously, can crash the v2 conhost with a recent Insiders build. Steps: 1. Open a cmd/powershell console window. 2. Open the console properties and uncheck the "Layout > Wrap text output on resize" option. 3. Run the test program I included. 4. The console window disappears. ## What's wrong / what should be happening instead: `SetConsoleScreenBufferInfoEx` shouldn't crash. The text `Hello?` should appear, and the console should return control to cmd/powershell. Aside 1: I don't think this affects winpty at all. Aside 2: `SetConsoleScreenBufferInfoEx` seems to handle `srWindow` differently than both `SetConsoleWindowInfo` and `GetConsoleScreenBufferInfoEx`. It tends to set the window size to 1 less width/height than the requested size, so a pair of calls to `GetConsoleScreenBufferInfoEx` and `SetConsoleScreenBufferInfoEx` shrinks the console window. ## Test program ```c++ #include <windows.h> #include <stdio.h> int main(int argc, char *argv[]) { HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFOEX info = { sizeof(info) }; GetConsoleScreenBufferInfoEx(conout, &info); info.dwSize.X = 120; info.dwSize.Y = 5000; info.srWindow.Left = info.srWindow.Top = 0; info.srWindow.Right = 121; info.srWindow.Bottom = 26; SetConsoleScreenBufferInfoEx(conout, &info); SetConsoleCursorPosition(conout, COORD { 0, 4000 }); info.dwSize.X = 80; info.dwSize.Y = 20; info.srWindow.Right = 41; info.srWindow.Bottom = 11; SetConsoleScreenBufferInfoEx(conout, &info); printf("Hello?\n"); return 0; } ```
claunia added the Product-ConhostWork-ItemNeeds-Repro labels 2026-01-30 21:50:18 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Sep 17, 2018):

Thanks for the bug report, I've filed msft:19013486 to make sure this gets fixed ASAP :)

@zadjii-msft commented on GitHub (Sep 17, 2018): Thanks for the bug report, I've filed msft:19013486 to make sure this gets fixed ASAP :)
Author
Owner

@miniksa commented on GitHub (Jan 4, 2019):

I'm not able to reproduce this issue anymore. Perhaps we fixed it?

If it's still crashing for you, can you try to find the report ID so I can maybe correlate it?
It should be in the Event Viewer under Windows Logs > Application.

I believe it's Event ID 1000 for Application Error (and should contain conhost.exe as the faulting application path with a report ID GUID that you can give to me).

@miniksa commented on GitHub (Jan 4, 2019): I'm not able to reproduce this issue anymore. Perhaps we fixed it? If it's still crashing for you, can you try to find the report ID so I can maybe correlate it? It should be in the Event Viewer under Windows Logs > Application. I believe it's Event ID 1000 for Application Error (and should contain conhost.exe as the faulting application path with a report ID GUID that you can give to me).
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 6, 2019):

Closing this for now. If you can get the report ID from a recent repro of this crash, we'd love to take a look. Thanks!

@DHowett-MSFT commented on GitHub (Feb 6, 2019): Closing this for now. If you can get the report ID from a recent repro of this crash, we'd love to take a look. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#377