Skip to content

v2 conhost crash with SetConsoleScreenBufferInfoEx calls #256

@rprichard

Description

@rprichard
  • 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;
}

Metadata

Metadata

Assignees

Labels

Needs-ReproWe can't figure out how to make this happen. Please help find a simplified repro.Product-ConhostFor issues in the Console codebaseWork-ItemIt's being tracked by an actual work item internally. (to be removed soon)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions