GetConsoleScreenBufferInfoEx + SetConsoleScreenBufferInfoEx screws up the size #18844

Open
opened 2026-01-31 06:26:05 +00:00 by claunia · 0 comments
Owner

Originally created by @alabuzhev on GitHub (Nov 8, 2022).

Windows Terminal version

1.16.2641.0

Windows build number

10.0.19044.2006

Other Software

No response

Steps to reproduce

  1. Compile the following little program:
#include <cassert>
#include <windows.h>

int main()
{
	for (;;)
	{
		const auto out = GetStdHandle(STD_OUTPUT_HANDLE);
		CONSOLE_SCREEN_BUFFER_INFOEX csbi{ sizeof(csbi) };

		if (!GetConsoleScreenBufferInfoEx(out, &csbi))
			assert(false);

		if (!SetConsoleScreenBufferInfoEx(out, &csbi))
			assert(false);

		system("pause");
	}
}
  1. Run it.
  2. Follow the instructions on the screen.

Expected Behavior

Nothing should happen, because nothing has been changed in the structure.

Actual Behavior

In conhost: the window size decreases on each iteration, eventually the window disappears.
In WT: the buffer size decreases on each iteration, eventually OpenConsole crashes.

More

The issue is not synthetic: CSBI allows to change other information than window/buffer sizes, e.g. the color palette (I know that OSC 4 exists).
If I am only changing the palette, I do not expect changes in the sizes.

Ironically, sequential SetConsoleScreenBufferSize + SetConsoleWindowInfo calls seem to work as expected:

#include <cassert>
#include <windows.h>

int main()
{
	for (;;)
	{
		const auto out = GetStdHandle(STD_OUTPUT_HANDLE);
		CONSOLE_SCREEN_BUFFER_INFOEX csbi{ sizeof(csbi) };

		if (!GetConsoleScreenBufferInfoEx(out, &csbi))
			assert(false);

		// These work fine in any order
		if (!SetConsoleScreenBufferSize(out, csbi.dwSize))
			assert(false);

		if (!SetConsoleWindowInfo(out, true, &csbi.srWindow))
			assert(false);

		system("pause");
	}
}
Originally created by @alabuzhev on GitHub (Nov 8, 2022). ### Windows Terminal version 1.16.2641.0 ### Windows build number 10.0.19044.2006 ### Other Software _No response_ ### Steps to reproduce 1. Compile the following little program: ```C++ #include <cassert> #include <windows.h> int main() { for (;;) { const auto out = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFOEX csbi{ sizeof(csbi) }; if (!GetConsoleScreenBufferInfoEx(out, &csbi)) assert(false); if (!SetConsoleScreenBufferInfoEx(out, &csbi)) assert(false); system("pause"); } } ``` 2. Run it. 3. Follow the instructions on the screen. ### Expected Behavior Nothing should happen, because nothing has been changed in the structure. ### Actual Behavior In conhost: the window size decreases on each iteration, eventually the window disappears. In WT: the buffer size decreases on each iteration, eventually OpenConsole crashes. ### More The issue is not synthetic: CSBI allows to change other information than window/buffer sizes, e.g. the color palette (I know that `OSC 4` exists). If I am only changing the palette, I do not expect changes in the sizes. Ironically, sequential `SetConsoleScreenBufferSize` + `SetConsoleWindowInfo` calls seem to work as expected: ```C++ #include <cassert> #include <windows.h> int main() { for (;;) { const auto out = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFOEX csbi{ sizeof(csbi) }; if (!GetConsoleScreenBufferInfoEx(out, &csbi)) assert(false); // These work fine in any order if (!SetConsoleScreenBufferSize(out, csbi.dwSize)) assert(false); if (!SetConsoleWindowInfo(out, true, &csbi.srWindow)) assert(false); system("pause"); } } ```
claunia added the Product-ConhostResolution-By-DesignIssue-BugArea-Server labels 2026-01-31 06:26:06 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18844