fix(core): bound bracketed-paste memory retention - #1320
Open
HARIOM-JHA01 wants to merge 1 commit into
Open
Conversation
An unterminated bracketed paste grew unbounded memory and left the parser stuck in paste mode: body bytes were retained without limit and only ESC[201~ could recover input. Introduce maxPasteBytes (default 16 MiB) and drop an over-limit paste in full when its end marker arrives, while still scanning for the marker so normal input resumes and oversized bytes never leak into key/mouse/response events.
HARIOM-JHA01
requested review from
Hona,
kommander,
msmps and
simonklee
as code owners
August 2, 2026 09:38
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 #1270
What
An unterminated bracketed paste (
ESC[200~with no matchingESC[201~) grew memory without bound and left theStdinParserstuck in paste mode. This PR bounds the memory retained for a single paste and makes over-limit pastes fail visibly instead of leaking bytes.Invariants satisfied
pasteevent.ESC[201~using only a small sliding tail, so a marker split across chunks or across the size boundary is still recognized and normal input resumes afterward.How
packages/core/src/lib/stdin-parser.tsaddsmaxPasteBytes(default 16 MiB) toStdinParserOptionsandPasteCollector.overLimit. Once an accumulated body would exceed the limit,pushPasteBytesstops retaining and freesparts;consumePasteBytesstill scans for the end marker but skips emitting the paste event.packages/core/src/lib/stdin-parser.test.tsadds six regression tests covering the limit boundary, full drop, no event leakage, recovery after the marker, a marker split across the size boundary, and a paste split across many small chunks.Testing
bun test src/lib/stdin-parser.test.ts: 427 passed, 0 failed.bunx oxfmt --checkandbunx oxlintclean on both changed files.