fix(staging): prevent index out of bounds when unstaging at buffer end#2966
Open
xfocus3 wants to merge 1 commit into
Open
fix(staging): prevent index out of bounds when unstaging at buffer end#2966xfocus3 wants to merge 1 commit into
xfocus3 wants to merge 1 commit into
Conversation
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
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.
Fixes #2953
When unstaging lines near the end of a diff buffer,
old_indexcould reachold_lines.len(), causing an index out of bounds panic inadd_old_line. Add a bounds check to handle this edge case gracefully.Changes
asyncgit/src/sync/staging/mod.rs: Added bounds check inadd_old_lineto prevent panic whenold_index >= old_lines.len()Verification
cargo checkpasses (full build requires OpenSSL dev package which is not available in this environment)Root Cause
The panic occurred at
asyncgit/src/sync/staging/mod.rs:42:25with 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.