{{ message }}
Repository navigation
fix(buffer): guard set_stringn against out-of-area coordinates (#2810) - #2850
Merged
joshka merged 2 commits intoOct 21, 2026
Merged
Conversation
ronitgupta138
added a commit
to ronitgupta138/ronitgupta138
that referenced
this pull request
Oct 20, 2026
…ui#2810) Buffer::set_stringn previously only calculated remaining width based on x and self.area.right(), without checking if y or x fell outside the buffer's bounded Rect. When multi-row layouts are rendered into degenerate or collapsed terminal viewports (e.g. 57x1 in tmux or narrow splits), writing to row y >= 1 indexed out of bounds into the buffer, triggering a panic in Buffer::index_of. Add boundary checks in Buffer::set_stringn to early return (x, y) if y is outside [area.top(), area.bottom()) or x >= area.right(), preventing panics during degenerate renders without mutating buffer state. Signed-off-by: Ronit Gupta <ronitgupta138@gmail.com>
ronitgupta138
force-pushed
the
fix/buffer-index-degenerate-rect
branch
from
October 20, 2026 20:07
8813bc3 to
8d85101
Compare
Member
joshka
approved these changes
Oct 21, 2026
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
In #2810,
Buffer::set_stringnpanicked when called with coordinates outside the buffer's area (e.g., in a 57x1 terminal split inside tmux where a multi-row layout writes to rowy = 1).Buffer::set_stringncomputedremaining_widthfromself.area.right().saturating_sub(x), but did not verify whetheryfell within[area.top(), area.bottom())or whetherxwas already outside the area. Writing toself[(x, y)]subsequently panicked inBuffer::index_of.Solution
Add an early-return guard at the start of
Buffer::set_stringn:If coordinates fall outside the buffer area, it safely early returns without mutating buffer contents or panicking, mirroring the safe behavior in
Buffer::set_style.Added unit test
set_stringn_does_not_panic_when_out_of_areainratatui-core/src/buffer/buffer.rs.Fixes #2810.