[PR #5200] [MERGED] Clamp VT parameter values to 32767 #26165

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/5200
Author: @j4james
Created: 4/1/2020
Status: Merged
Merged: 4/1/2020
Merged by: @undefined

Base: masterHead: clamp-vt-parameters


📝 Commits (1)

  • d2690a0 Clamp parameter values to a maximum of 32767.

📊 Changes

3 files changed (+27 additions, -15 deletions)

View changed files

📝 src/terminal/parser/stateMachine.cpp (+9 -8)
📝 src/terminal/parser/stateMachine.hpp (+9 -3)
📝 src/terminal/parser/ut_parser/OutputEngineTest.cpp (+9 -4)

📄 Description

Summary of the Pull Request

This PR clamps the parameter values in the VT StateMachine parser to 32767, which was the initial limit prior to PR #3956. This fixes a number of overflow bugs (some of which could cause the app to crash), since much of the code is not prepared to handle values outside the range of a short.

References

#3956 - the PR where the cap was changed to the range of size_t
#4254 - one example of a crash caused by the higher range

PR Checklist

  • Closes a white screen occurs when I drag the windows terminal (#5160)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

The DEC STD 070 reference recommends supporting up to at least 16384 for parameter values, so 32767 should be more than enough for any standard VT sequence. It might be nice to increase the limit to 65535 at some point, since that is the cap used by both XTerm and VTE. However, that is not essential, since there are very few situations where you'd even notice the difference. For now, 32767 is the safest choice for us, since anything greater than that has the potential to overflow and crash the app in a number of places.

Validation Steps Performed

I had to make a couple of modifications to the range checks in the OutputEngineTest, more or less reverting to the pre-#3956 behavior, but after that all of the unit tests passed as expected.

I manually confirmed that this fixes the hanging test case from #5160, as well as overflow issues in the cursor operations, and crashes in IL and DL (see https://github.com/microsoft/terminal/issues/4254#issuecomment-575292926).


🔄 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/5200 **Author:** [@j4james](https://github.com/j4james) **Created:** 4/1/2020 **Status:** ✅ Merged **Merged:** 4/1/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `clamp-vt-parameters` --- ### 📝 Commits (1) - [`d2690a0`](https://github.com/microsoft/terminal/commit/d2690a0ecac2ab9f7f65c62998af875634a4c491) Clamp parameter values to a maximum of 32767. ### 📊 Changes **3 files changed** (+27 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `src/terminal/parser/stateMachine.cpp` (+9 -8) 📝 `src/terminal/parser/stateMachine.hpp` (+9 -3) 📝 `src/terminal/parser/ut_parser/OutputEngineTest.cpp` (+9 -4) </details> ### 📄 Description ## Summary of the Pull Request This PR clamps the parameter values in the VT `StateMachine` parser to 32767, which was the initial limit prior to PR #3956. This fixes a number of overflow bugs (some of which could cause the app to crash), since much of the code is not prepared to handle values outside the range of a `short`. ## References #3956 - the PR where the cap was changed to the range of `size_t` #4254 - one example of a crash caused by the higher range ## PR Checklist * [x] Closes #5160 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments The DEC STD 070 reference recommends supporting up to at least 16384 for parameter values, so 32767 should be more than enough for any standard VT sequence. It might be nice to increase the limit to 65535 at some point, since that is the cap used by both XTerm and VTE. However, that is not essential, since there are very few situations where you'd even notice the difference. For now, 32767 is the safest choice for us, since anything greater than that has the potential to overflow and crash the app in a number of places. ## Validation Steps Performed I had to make a couple of modifications to the range checks in the `OutputEngineTest`, more or less reverting to the pre-#3956 behavior, but after that all of the unit tests passed as expected. I manually confirmed that this fixes the hanging test case from #5160, as well as overflow issues in the cursor operations, and crashes in `IL` and `DL` (see https://github.com/microsoft/terminal/issues/4254#issuecomment-575292926). --- <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:14:22 +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#26165