Skip to content

fix(staging): prevent index out of bounds when unstaging at buffer end#2966

Open
xfocus3 wants to merge 1 commit into
gitui-org:masterfrom
xfocus3:fix/unstage-index-out-of-bounds-2953
Open

fix(staging): prevent index out of bounds when unstaging at buffer end#2966
xfocus3 wants to merge 1 commit into
gitui-org:masterfrom
xfocus3:fix/unstage-index-out-of-bounds-2953

Conversation

@xfocus3

@xfocus3 xfocus3 commented Jun 17, 2026

Copy link
Copy Markdown

Fixes #2953

When unstaging lines near the end of a diff buffer, old_index could reach old_lines.len(), causing an index out of bounds panic in add_old_line. Add a bounds check to handle this edge case gracefully.

Changes

  • asyncgit/src/sync/staging/mod.rs: Added bounds check in add_old_line to prevent panic when old_index >= old_lines.len()

Verification

  • cargo check passes (full build requires OpenSSL dev package which is not available in this environment)
  • Fix is a minimal, defensive bounds check that prevents the panic without changing behavior for valid inputs

Root Cause

The panic occurred at asyncgit/src/sync/staging/mod.rs:42:25 with message: index out of bounds: the len is 151 but the index is 151. This happened when pressing 's' (Unstage lines) at almost the end of the buffer in the Diff view.

When unstaging lines near the end of a diff buffer, old_index could
reach old_lines.len(), causing an index out of bounds panic in
add_old_line. Add a bounds check to handle this edge case gracefully.

Fixes gitui-org#2953
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.

Index out of bounds

1 participant