Skip to content

Fix panic when cursor is exhausted during fold/unfold - #48802

Closed
rtfeldman wants to merge 1 commit into
mainfrom
fix/block-map-sync-unwrap-panic
Closed

Fix panic when cursor is exhausted during fold/unfold#48802
rtfeldman wants to merge 1 commit into
mainfrom
fix/block-map-sync-unwrap-panic

Conversation

@rtfeldman

Copy link
Copy Markdown
Contributor

The crash was a .unwrap() on None at an exhausted SumTree cursor inside BlockMap::sync. This happens when the transforms tree has fewer input_rows than the wrap snapshot expects — an inconsistency from a prior sync that was only guarded by a debug_assert (compiled out in release builds).

The call chain leading to the crash:

Editor::on_buffer_event
→ DisplayMap::unfold_buffers
→ BlockMapWriter::fold_or_unfold_buffers
→ BlockMap::sync  ← cursor.item().unwrap() panics

Fix:

  • Replace the .unwrap() with graceful None handling: log an error, consume remaining edits, and rebuild blocks for the remaining range.
  • Add a log::error! at the input_rows invariant check so inconsistencies are visible in release builds (alongside the existing debug_assert).

Release Notes:

  • Fixed a crash that could occur when folding or unfolding buffers in the editor.

The crash occurred at an .unwrap() on cursor.item() in BlockMap::sync
(line 891) when the SumTree cursor had been exhausted. This happens when
the transforms tree has fewer input_rows than the wrap snapshot expects,
which can occur when a prior sync produces an inconsistent state (only
caught by a debug_assert in release builds).

The call chain was:
  Editor::on_buffer_event
  → DisplayMap::unfold_buffers
  → BlockMapWriter::fold_or_unfold_buffers
  → BlockMap::sync

Fix: Replace the .unwrap() with graceful handling — when the cursor is
exhausted, log an error, consume all remaining edits, and rebuild blocks
for the remaining range. Also add a log::error at the input_rows
invariant check so inconsistencies are visible in release builds.
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Feb 9, 2026
@rtfeldman rtfeldman changed the title Fix panic in BlockMap::sync when cursor is exhausted during fold/unfold Fix panic when cursor is exhausted during fold/unfold Feb 9, 2026
@cole-miller

cole-miller commented Feb 9, 2026

Copy link
Copy Markdown
Member

@rtfeldman I believe the panic here is fixed by #48809--I think we should close in favor of that since it targets the specific code that regressed here (due to my earlier PR)

@rtfeldman

Copy link
Copy Markdown
Contributor Author

Cool, thanks! 🚀

@rtfeldman rtfeldman closed this Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants