microsoft / microsoft/terminal
Crash when resizing openconsole to 0 rows (was: `std::clamp`ing the cursor, 2023 edition)
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
> @zadjii-msft I think we may want to reopen this issue. I was just testing PR #14661, which kind of reverts your fix for this, and I wanted to make sure I hadn't reintroduced the bug. What I discovered was that the issue was never fully resolved - while we don't get a clamp assertion in the cursor code, we now just get it somewhere else instead! For me it occurred here:
>
> https://github.com/microsoft/terminal/blob/4d27a05318f4e86b0918497ba6f980968725a1d2/src/terminal/adapter/adaptDispatch.cpp#L219
>
> And I double checked with the commit from when PR #13001 was merged (79904361b345b68f4612d41b390c4eb3f3d18fae), and it was already failing then. It may not be obvious in some shells, but in a WSL bash shell it crashes straight away. In a cmd shell I had to type some command (e.g. `CLS`) while the window had a zero size in order to trigger the crash.
>
> It's not a major problem, since it only happens in a debug build, but if we think it needs fixing we should probably reopen this, or at least open another issue if you prefer that.
>
> As for how we fix it, I would have liked it if we could put a minimum size on the viewport, but I suspect that's not possible in conhost for legacy reasons. So failing that, a quick fix would be to replace the clamp calls with a min/max combo which won't assert. But my concern is that the VT architecture is kind of dependent on a non-zero screen size, so there's a fair chance this issue might just surface elsewhere at some point in the future. Maybe we just have to accept that.
>
_Originally posted by @j4james in https://github.com/microsoft/terminal/issues/12917#issuecomment-1378073019_
Contributor guide
Research direction
Start at src/terminal/adapter/adaptDispatch.cpp line 219 and reproduce the crash by resizing openconsole to zero rows, using WSL bash or a cmd shell as described. Trace the zero-size viewport handling and check whether the issue is limited to debug assertions or surfaces elsewhere. Done means the zero-row scenario no longer crashes or triggers an assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100