From c4f0c544d456cda007399c910fccaadcd3c8611e Mon Sep 17 00:00:00 2001 From: Ahmed El amraouiyine Date: Wed, 17 Jun 2026 05:25:22 +0100 Subject: [PATCH] fix(staging): prevent index out of bounds when unstaging at buffer end 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 #2953 --- asyncgit/src/sync/staging/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/asyncgit/src/sync/staging/mod.rs b/asyncgit/src/sync/staging/mod.rs index fc16340811..9541da4385 100644 --- a/asyncgit/src/sync/staging/mod.rs +++ b/asyncgit/src/sync/staging/mod.rs @@ -39,8 +39,10 @@ impl NewFromOldContent { } fn add_old_line(&mut self, old_lines: &[&str]) { - self.lines.push(old_lines[self.old_index].to_string()); - self.old_index += 1; + if self.old_index < old_lines.len() { + self.lines.push(old_lines[self.old_index].to_string()); + self.old_index += 1; + } } fn catchup_to_hunkstart(