fix: prevent panic when filtered PTY output exceeds read buffer - #67
Merged
Conversation
TerminalOutputFilter carries partial control sequences across reads, so a single filter() call can emit more bytes than the chunk it consumed (carried-over pending + current chunk). read_pty() copied the filtered bytes back into the fixed 64KiB read buffer, which panics in copy_from_slice when a large sequence (e.g. an OSC 52 clipboard payload larger than the buffer) flushes on a full read. Append filtered output to a caller-provided Vec instead of writing back into the read buffer, and return the raw byte count so EOF detection is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ttak0422
marked this pull request as ready for review
July 4, 2026 15:26
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.
Problem
TerminalOutputFiltercarries partial control sequences across reads in itspendingbuffer, so a singlefilter()call can emit more bytes than the chunk it consumed (carried-over pending + current chunk).read_pty()copied the filtered bytes back into the fixed 64KiB read buffer:Reproduction path: an OSC 52 clipboard payload larger than the read buffer accumulates in
pendingacross reads; when its terminator arrives on a full 64KiB read,filtered_len > buf.len()and the daemon panics — killing the session.Fix
read_pty()now appends filtered output to a caller-providedVec(pending_pty_outputin the server drain loop) instead of writing back into the read buffer, and returns the raw byte count so EOF detection (Ok(0)) is unchanged. The type change removes the overflow class entirely — no size assumption left to violate.Added
terminal_output_filter_output_can_exceed_input_chunkto pin the invariant that motivated the API shape.Verification
cargo test: 31 passedcargo clippy --all-targets: clean🤖 Generated with Claude Code