selection_extract: clamp row index before grid access (fixes segfault on drag-to-other-window)#3
Open
blshkv wants to merge 1 commit into
Open
Conversation
sel_start_row/sel_end_row can legitimately exceed MAX_ROWS-1 during
scrollback selection (incremented in lockstep with scroll_offset so
the .se_row_grid_shifted path keeps them in bounds). If scroll_offset
is reset to 0 before a SelectionRequest arrives (e.g. the user drags
selected text to another window after the viewport snapped back), the
.se_row_live path fires instead and computes
grid + r12 * MAX_COLS * CELL_SIZE
with r12 >= MAX_ROWS, producing an out-of-bounds read and segfault.
Add a MAX_ROWS guard in both .se_row_live and .se_row_grid_shifted
before the imul/lea sequence. An out-of-range row jumps to .se_done,
truncating the selection at the valid region rather than crashing.
Fixes: isene#2
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
blshkv
force-pushed
the
fix/selection-extract-oob-segfault
branch
from
July 21, 2026 14:15
10cd293 to
c28ec4c
Compare
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.
Closes #2
sel_start_rowandsel_end_roware clamped toMAX_ROWS-1during normal operation, butselection_extractcomputes a shifted row index that can exceedMAX_ROWS-1when the selection extends into the scrollback buffer andscroll_offsetis non-zero. The resultinggridpointer lands past the end of the buffer, causing a segfault.Fix: add bounds checks before both grid-pointer computations in
selection_extract.🤖 Generated with Claude Code