terminal: cmd.exe always hang if calling SetConsoleScreenBufferSize at bottom line
Environment
Microsoft Windows [Version 10.0.18362.239]
Steps to reproduce
Sorry, I don’t figure out clearly but this step always make cmd.exe hang. At present, the method that can be reliably reproduced is to start vim.exe at the bottom line of cmd.exe.
Expected behavior
Do not hang.
Actual behavior
Hang.
FYI, I tried to run this code, but not reproduce.
#include <windows.h>
int
main(int argc, char* argv[]) {
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
coord.X = 80;
coord.Y = 300;
SetConsoleScreenBufferSize(h, coord);
return 0;
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 23 (5 by maintainers)
Commits related to this issue
- Fix out-of-bounds exceptions in Set...{Buffer,Screen}Size (#8309) This fixes a number of exceptions that can cause conhost to crash when the buffer is resized in such a way that the viewport or curs... — committed to microsoft/terminal by j4james 4 years ago
- Fix out-of-bounds exceptions in Set...{Buffer,Screen}Size (#8309) This fixes a number of exceptions that can cause conhost to crash when the buffer is resized in such a way that the viewport or curso... — committed to microsoft/terminal by j4james 4 years ago
I can reproduce this fairly easily in the debugger (or at least a very similar issue). The trick, in my case, is to have the Wrap test output on resize option unchecked in the Layout properties. Then the easiest way to trigger it is with a
printfin a bash shell:The
sleepisn’t always required, but it seems to help in some situations, assumedly because it needs time to trigger before the prompt is displayed and the cursor repositions itself.In the debugger I can see that it’s crashing when trying to paint the cursor while out of bounds (the buffer width is 40, while the y pos is at 80). Here’s the key part of my call stack (on commit 4b439cf290d74caf61041803846df81a75f28919):
I’m almost certain I’ve had this crash with a manual resize as well, although I haven’t now been able to reproduce that.
I guess that the cause of this bug is related on cursor location. If the cursor position is out of bounds of RESIZED size, cmdhost.exe crash.