[PR #843] [MERGED] Fix #453: Setting historySize=32767 causes WindowsTerminal to hang #24343

Open
opened 2026-01-31 09:02:42 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/843
Author: @metathinker
Created: 5/16/2019
Status: Merged
Merged: 5/18/2019
Merged by: @undefined

Base: masterHead: fix-historysize-32767


📝 Commits (9)

  • 3b8f255 fix for historySize=32767 hang (except for historySize=0 case); tests still in progress
  • ba59327 tests run and almost pass - failure is a real bug in my change
  • 271a011 fixed bug that caused tests to fail, but it seems another bug causes the app to crash with a zero row count
  • d247731 fix the additional bug (at a higher layer) mentioned in previous commit description
  • 8d03d43 Fix chk build assertion failures in new tests
  • 2049150 Merge branch 'master' (e3764b2081) into fix-historysize-32767 (8d03d437ba)
  • c20a19d tabs to spaces
  • c848805 CR feedback
  • 407aee4 fix minor CR feedback (incorrect test log message)

📊 Changes

6 files changed (+158 additions, -10 deletions)

View changed files

📝 src/cascadia/TerminalControl/TermControl.cpp (+5 -2)
📝 src/cascadia/TerminalCore/Terminal.cpp (+11 -6)
src/cascadia/UnitTests_TerminalCore/ScreenSizeLimitsTest.cpp (+136 -0)
📝 src/cascadia/UnitTests_TerminalCore/UnitTests.vcxproj (+4 -2)
📝 src/inc/LibraryIncludes.h (+1 -0)
📝 tools/runut.cmd (+1 -0)

📄 Description

With this change, setting the scrollback history size (number of scrollback rows) to more than about 32,000 will no longer cause Windows Terminal to hang forever.

The problem was indeed what @zadjii-msft said it might be in the bug - the history size is persisted into profiles.json as a 32-bit signed integer (well, really a JSON/JS number, but the internal data models use 32-bit ints), but was being coerced without overflow checks into 16 bits, and the bug was the overflow in question. The fix was to clamp the history size read in to a non-negative 16-bit signed integer.

I also took the liberty of adding similar overflow/underflow clamping for the initial number of rows and columns in the window.

Testing:

No doc changes made or required
Fixes #453


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/843 **Author:** [@metathinker](https://github.com/metathinker) **Created:** 5/16/2019 **Status:** ✅ Merged **Merged:** 5/18/2019 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `fix-historysize-32767` --- ### 📝 Commits (9) - [`3b8f255`](https://github.com/microsoft/terminal/commit/3b8f2559701b55255141b13403b4e9fa41725f01) fix for historySize=32767 hang (except for historySize=0 case); tests still in progress - [`ba59327`](https://github.com/microsoft/terminal/commit/ba59327f71d9cceb05af25ef060be3d8bd0ce9f2) tests run and almost pass - failure is a real bug in my change - [`271a011`](https://github.com/microsoft/terminal/commit/271a011d8b213863ae3782fc1a1e0f6cc4fa6e67) fixed bug that caused tests to fail, but it seems another bug causes the app to crash with a zero row count - [`d247731`](https://github.com/microsoft/terminal/commit/d2477318d6e94e7e7f048e6b67df28c4f0f3c9bd) fix the additional bug (at a higher layer) mentioned in previous commit description - [`8d03d43`](https://github.com/microsoft/terminal/commit/8d03d437bacf6c75cb13526ef721167d3140bd39) Fix chk build assertion failures in new tests - [`2049150`](https://github.com/microsoft/terminal/commit/204915077cceb7fcda0b1d149d3df5ea7534ed7f) Merge branch 'master' (e3764b2081b74c67fb901b2c133380c5bd3787af) into fix-historysize-32767 (8d03d437bacf6c75cb13526ef721167d3140bd39) - [`c20a19d`](https://github.com/microsoft/terminal/commit/c20a19d15baa827cc79233e486cc3ca2aa36569b) tabs to spaces - [`c848805`](https://github.com/microsoft/terminal/commit/c84880500660a69f4a63272e814d8b619ad78ba2) CR feedback - [`407aee4`](https://github.com/microsoft/terminal/commit/407aee48aa5689c321177d66803a2189692172c9) fix minor CR feedback (incorrect test log message) ### 📊 Changes **6 files changed** (+158 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+5 -2) 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+11 -6) ➕ `src/cascadia/UnitTests_TerminalCore/ScreenSizeLimitsTest.cpp` (+136 -0) 📝 `src/cascadia/UnitTests_TerminalCore/UnitTests.vcxproj` (+4 -2) 📝 `src/inc/LibraryIncludes.h` (+1 -0) 📝 `tools/runut.cmd` (+1 -0) </details> ### 📄 Description With this change, setting the scrollback history size (number of scrollback rows) to more than about 32,000 will no longer cause Windows Terminal to hang forever. The problem was indeed what @zadjii-msft said it might be in the bug - the history size is persisted into profiles.json as a 32-bit signed integer (well, really a JSON/JS number, but the internal data models use 32-bit ints), but was being coerced without overflow checks into 16 bits, and the bug was the overflow in question. The fix was to clamp the history size read in to a non-negative 16-bit signed integer. I also took the liberty of adding similar overflow/underflow clamping for the initial number of rows and columns in the window. Testing: - manual - CI build and test passes, including new unit tests I added: https://dev.azure.com/ms/Terminal/_build/results?buildId=15717 (note: the TerminalControl changes aren't currently tested as I couldn't find any existing test scaffolding) No doc changes made or required Fixes #453 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:02:42 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#24343