Repository navigation
Clamp line count in SU, SD, IL and DL to the scroll region - #6318
Open
breeezly1228 wants to merge 1 commit into
Open
breeezly1228 wants to merge 1 commit into
breeezly1228 wants to merge 1 commit into
Conversation
scrollUp, scrollDown, insertLines and deleteLines looped once per requested line with no upper bound, so a CSI parameter up to 2147483647 (e.g. ESC[22936629T, 11 bytes) blocked the main thread for tens of seconds to tens of minutes. Repeating past the number of lines in the affected range does not change the buffer, so clamp the count to that range. Add regression tests that fail immediately if the clamp is removed. Fixes xtermjs#6317 Prepared with AI assistance (Google Gemini, OpenAI Codex, Anthropic Claude). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6317
What
Clamps the line count parameter (
param) insrc/common/InputHandler.ts:scrollUp(CSI Ps S) andscrollDown(CSI Ps T,CSI Ps ^):insertLines(CSI Ps L) anddeleteLines(CSI Ps M):Why
EscapeSequenceParserallows CSI numeric parameters up toMAX_INT(2147483647). Previously,scrollUp,scrollDown,insertLines, anddeleteLinesexecutedwhile (param--)directly with the unclamped parameter. Passing a large parameter (e.g.\x1b[22936629Tor\x1b[2147483647T) caused tens of millions to billions ofCircularList.spliceandBuffer.getBlankLinecalls, blocking the main thread for tens of seconds to tens of minutes.Because all four methods operate in-place within the active scroll region (
[scrollTop, scrollBottom]forSU/SDand[y, scrollBottom]forIL/DL), clampingparamto the number of lines in the affected range produces the same final buffer, scrollback, cursor, and marker state while bounding loop iterations to at mostrows.Testing
describe('scroll margins', ...)insrc/common/InputHandler.test.ts. Each test sendsPs = 2147483647, checks the final buffer contents, and wrapsbuffer.lines.spliceso that more line operations than the affected range allows fail the test immediately.npm run build && npm run esbuild; all 198 tests inout-esbuild/common/InputHandler.test.jspass.expected at most 6 line operations, got 7) in 0–5 ms per test, instead of running billions of iterations. Restored the clamps, rebuilt, and reran all 198 tests successfully.DECSTBMscroll regions,DECOMorigin mode, wrapped lines, SGR erase attributes, cursor positions and line markers: 10,000 trials on anInputHandlerharness and 2,000 trials on full headlessTerminalinstances viaterm.write(...), with 0 mismatches.Disclosure: The investigation, patch and tests were prepared with AI assistance (Google Gemini, OpenAI Codex, Anthropic Claude). I reviewed the write-up before submitting.
🤖 Generated with Claude Code