Terminal crashes on startup when initial rows on screen (initialRows setting) is set too high #1168

Closed
opened 2026-01-30 22:17:58 +00:00 by claunia · 9 comments
Owner

Originally created by @metathinker on GitHub (May 16, 2019).

Using this commit: e3764b2081

  1. Make sure there is no existing Terminal settings file at: %LocalAppData%\Packages\WindowsTerminalDev_8wekyb3d8bbwe\RoamingState\profiles.json
  2. Build Terminal with tools\razzle.cmd & bcz.
  3. Open the OpenConsole.sln in Visual Studio, select debug/release and CPU architecture to match your build, and hit F5 to deploy and run the Terminal .appx package.
  4. Open the newly created Terminal settings file, and change the initialRows setting from 30 to 1637.
  5. Close and restart Terminal.

Observe that Terminal does not start at all. If you start Terminal under a debugger, you'll see that the release build crashes with an unhandled C++ exception. (I haven't tried the debug build.)

Setting initialRows to 1636 or less does not cause the problem, but setting it to 1637 (as above) or greater does cause it.

Originally posted by @metathinker in https://github.com/microsoft/terminal/pull/843#discussion_r284818080 - that PR does not fix or otherwise affect this bug.

Originally created by @metathinker on GitHub (May 16, 2019). Using this commit: e3764b2081b74c67fb901b2c133380c5bd3787af 1. Make sure there is no existing Terminal settings file at: `%LocalAppData%\Packages\WindowsTerminalDev_8wekyb3d8bbwe\RoamingState\profiles.json` 2. Build Terminal with `tools\razzle.cmd & bcz`. 3. Open the OpenConsole.sln in Visual Studio, select debug/release and CPU architecture to match your build, and hit F5 to deploy and run the Terminal .appx package. 4. Open the newly created Terminal settings file, and change the `initialRows` setting from 30 to 1637. 5. Close and restart Terminal. Observe that Terminal does not start at all. If you start Terminal under a debugger, you'll see that the release build crashes with an unhandled C++ exception. (I haven't tried the debug build.) Setting `initialRows` to 1636 or less does not cause the problem, but setting it to 1637 (as above) or greater does cause it. _Originally posted by @metathinker in https://github.com/microsoft/terminal/pull/843#discussion_r284818080_ - that PR does not fix or otherwise affect this bug.
Author
Owner

@mKay00 commented on GitHub (May 16, 2019):

For me it crashes >= 820

@mKay00 commented on GitHub (May 16, 2019): For me it crashes >= 820
Author
Owner

@dkter commented on GitHub (May 19, 2019):

For me it crashes >= 1559 at 100% scaling. Changing my primary display resolution doesn't change the result but changing the scaling does (my primary display is 1920x1080, I have two other displays but they don't seem to be relevant):

Scaling Max value of initialRows
100% 1558
125% 1246
150% 1038
175% 889
@dkter commented on GitHub (May 19, 2019): For me it crashes >= 1559 at 100% scaling. Changing my primary display resolution doesn't change the result but changing the scaling does (my primary display is 1920x1080, I have two other displays but they don't seem to be relevant): | Scaling | Max value of `initialRows` | | -------- | ----------- | | 100% | 1558 | | 125% | 1246 | | 150% | 1038 | | 175% | 889 |
Author
Owner

@dkter commented on GitHub (May 20, 2019):

This definitely looks like an integer overflow issue. From https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalControl/TermControl.cpp#L1119 it looks like the program crashes when height > 32728.0.

Edit: At https://github.com/microsoft/terminal/blob/master/src/cascadia/WindowsTerminal/AppHost.cpp#L135 and https://github.com/microsoft/terminal/blob/master/src/cascadia/WindowsTerminal/AppHost.cpp#L176 the height is being gsl::narrowed to a short, which will cause a crash at either of those two places.

@dkter commented on GitHub (May 20, 2019): This definitely looks like an integer overflow issue. From https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalControl/TermControl.cpp#L1119 it looks like the program crashes when `height` > 32728.0. Edit: At https://github.com/microsoft/terminal/blob/master/src/cascadia/WindowsTerminal/AppHost.cpp#L135 and https://github.com/microsoft/terminal/blob/master/src/cascadia/WindowsTerminal/AppHost.cpp#L176 the height is being `gsl::narrow`ed to a short, which will cause a crash at either of those two places.
Author
Owner

@zadjii-msft commented on GitHub (May 20, 2019):

Great work finding that @dkter. Seems like a simple enough fix for someone to submit a PR for :)

@zadjii-msft commented on GitHub (May 20, 2019): Great work finding that @dkter. Seems like a simple enough fix for someone to submit a PR for :)
Author
Owner

@dkter commented on GitHub (May 21, 2019):

For consistency it might be helpful to use the existing _ClampToShortMax helper from #843, but it seems to be in Terminal.cpp -- is there a better place to put it?

@dkter commented on GitHub (May 21, 2019): For consistency it might be helpful to use the existing `_ClampToShortMax` helper from #843, but it seems to be in `Terminal.cpp` -- is there a better place to put it?
Author
Owner

@zadjii-msft commented on GitHub (May 21, 2019):

@dkter usually for things like that, we'll throw them in src/types/utils.cpp (and src/types/inc/utils.hpp). That's kinda our dependency-free helper lib that's used by a ton of things.

@zadjii-msft commented on GitHub (May 21, 2019): @dkter usually for things like that, we'll throw them in `src/types/utils.cpp` (and `src/types/inc/utils.hpp`). That's kinda our dependency-free helper lib that's used by a ton of things.
Author
Owner

@dkter commented on GitHub (Jun 2, 2019):

I wanted to add unit tests, but I wasn't sure where to put them for the WindowsTerminal project?

@dkter commented on GitHub (Jun 2, 2019): I wanted to add unit tests, but I wasn't sure where to put them for the `WindowsTerminal` project?
Author
Owner

@zadjii-msft commented on GitHub (Jun 3, 2019):

Right now the only tests we have are in src\cascadia\unittests_terminalcore, and they only really test the "TerminalCore" project. I'm working on adding a test framework for the rest of the projects, but that's proving to be a bit harder that we hoped (see #1042 for way more detail)

@zadjii-msft commented on GitHub (Jun 3, 2019): Right now the only tests we have are in `src\cascadia\unittests_terminalcore`, and they only really test the "TerminalCore" project. I'm working on adding a test framework for the rest of the projects, but that's proving to be a bit harder that we hoped (see #1042 for _way_ more detail)
Author
Owner

@Reelix commented on GitHub (Oct 24, 2019):

Even though this bug is closed, it still exists in the newly released Version 0.6.2951.0

@Reelix commented on GitHub (Oct 24, 2019): Even though this bug is closed, it still exists in the newly released Version 0.6.2951.0
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1168