Skip to content

fix: prevent panic when filtered PTY output exceeds read buffer - #67

Merged
ttak0422 merged 1 commit into
mainfrom
worktree-fix+read-pty-filter-panic
Jul 5, 2026
Merged

fix: prevent panic when filtered PTY output exceeds read buffer#67
ttak0422 merged 1 commit into
mainfrom
worktree-fix+read-pty-filter-panic

Conversation

@ttak0422

@ttak0422 ttak0422 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Problem

TerminalOutputFilter carries partial control sequences across reads in its pending buffer, 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:

let filtered_len = filtered.len();
buf[..filtered_len].copy_from_slice(&filtered); // panics when filtered_len > buf.len()

Reproduction path: an OSC 52 clipboard payload larger than the read buffer accumulates in pending across 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-provided Vec (pending_pty_output in 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_chunk to pin the invariant that motivated the API shape.

Verification

  • cargo test: 31 passed
  • cargo clippy --all-targets: clean

🤖 Generated with Claude Code

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
ttak0422 marked this pull request as ready for review July 4, 2026 15:26
@ttak0422
ttak0422 merged commit 859c7ca into main Jul 5, 2026
3 checks passed
@ttak0422
ttak0422 deleted the worktree-fix+read-pty-filter-panic branch July 5, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant