Draft crash fix for ZED-473 - #49401
Closed
github-actions[bot] wants to merge 1 commit into
Closed
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @factory-droid[bot] on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
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.
Fix slice index panic in SelectionsCollection::disjoint_in_range
Crash Summary
Sentry Issue: ZED-473 (1108 events)
The editor crashes with "slice index starts at X but ends at Y" when
disjoint_in_rangeis called during the prepaint phase with stale selection anchors that reference removed/modified excerpts.Root Cause
The
disjoint_in_rangefunction performs two binary searches to find selections within a given anchor range:start_ix: finds where selections end afterrange.startend_ix: finds where selections start beforerange.endWhen selections contain anchors pointing to excerpts that have been removed from the MultiBuffer, the anchor comparison logic can return inconsistent ordering results. This causes the binary searches to produce
start_ix > end_ix, which then panics when used as a slice range.The crash occurs during window layout/rendering (
EditorElement::prepaint), a timing-sensitive code path where the selection state can become temporarily inconsistent with the display snapshot after excerpt modifications.Fix
Added a guard to return an empty vector when
start_ix > end_ix, which indicates an inconsistent state where no valid selections exist in the requested range for the current snapshot:This is a defensive fix that prevents the panic while maintaining correct behavior - when selections reference stale excerpts, returning an empty result is appropriate since those selections don't actually exist in the current snapshot.
Validation
test_disjoint_in_range_with_stale_selectionsthat creates a MultiBuffer with excerpts, establishes selections, removes an excerpt, and callsdisjoint_in_range- previously would panic, now returns safely.Note: Full test suite validation requires X11 libraries which are not available in this CI environment. The test will be validated by CI on PR submission.
Release Notes:
Potentially Related Issues
Medium Confidence
#49237 — multi_buffer: Guard unresolved anchors during summary resolution
#49047 — multi_buffer: Fix "cannot seek backward" crash in summaries_for_anchors
#40249 — editor: Fix
SelectionsCollection::disjointnot being ordered correctlyLow Confidence
Reviewer Checklist
disjoint_in_rangedepend on non-empty resultsFixes #...) - none confirmed