Skip to content

buffer_diff: Fix panic when staging hunks with stale buffer snapshot (#51641) (cherry-pick to preview)#51643

Merged
zed-zippy[bot] merged 1 commit intov0.228.xfrom
cherry-pick-v0.228.x-ebd80d79
Mar 16, 2026
Merged

buffer_diff: Fix panic when staging hunks with stale buffer snapshot (#51641) (cherry-pick to preview)#51643
zed-zippy[bot] merged 1 commit intov0.228.xfrom
cherry-pick-v0.228.x-ebd80d79

Conversation

@zed-zippy
Copy link
Copy Markdown
Contributor

@zed-zippy zed-zippy bot commented Mar 16, 2026

Cherry-pick of #51641 to preview


When the buffer is edited after the diff is computed but before staging,
anchor positions shift while diff_base_byte_range values don't. If the
primary (HEAD) hunk extends past the unstaged (index) hunk, an edit in
the extension region causes the overshoot calculation to produce an
index_end that exceeds index_text.len(), panicking in
rope::Cursor::suffix.

Fix by clamping index_end to index_text.len(). This is safe because the
computed index text is an optimistic approximation — the real staging
happens at the filesystem level via git add/git reset.

Closes ZED-5R2

Release Notes:

  • Fixed a source of panics when staging diff hunks

…51641)

When the buffer is edited after the diff is computed but before staging,
anchor positions shift while diff_base_byte_range values don't. If the
primary (HEAD) hunk extends past the unstaged (index) hunk, an edit in
the extension region causes the overshoot calculation to produce an
index_end that exceeds index_text.len(), panicking in
rope::Cursor::suffix.

Fix by clamping index_end to index_text.len(). This is safe because the
computed index text is an optimistic approximation — the real staging
happens at the filesystem level via git add/git reset.

Closes ZED-5R2


Release Notes:

- Fixed a source of panics when staging diff hunks
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 16, 2026
@zed-community-bot zed-community-bot bot added the bot Pull requests authored by a bot label Mar 16, 2026
@zed-zippy zed-zippy bot merged commit e114a3a into v0.228.x Mar 16, 2026
39 checks passed
@zed-zippy zed-zippy bot deleted the cherry-pick-v0.228.x-ebd80d79 branch March 16, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot Pull requests authored by a bot cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant