editor: Fix underflow panic in block map sync when blocks overlap#51078
Merged
editor: Fix underflow panic in block map sync when blocks overlap#51078
Conversation
In `BlockMap::sync`, blocks within an edited region are sorted and processed sequentially. Each block placement computes `rows_before_block` by subtracting `new_transforms.summary().input_rows` from the block's target position. The `Near`/`Below` cases have a guard that skips the block if the target is already behind the current progress, but `Above` and `Replace` were missing this guard. When a `Replace` block (tie_break 0) is processed before an `Above` block (tie_break 1) at the same or overlapping position, the `Replace` block consumes multiple input rows, advancing `input_rows` past the `Above` block's position. The subsequent `position - input_rows` subtraction underflows on `u32`, producing a huge `RowDelta` that wraps `wrap_row_end` past `wrap_row_start`, creating an inverted range that propagates through the display map layers and panics as `begin <= end (47 <= 0)` in a rope chunk slice. Add underflow guards to `Above` and `Replace`, matching the existing pattern in `Near`/`Below`.
Member
Author
|
/cherry-pick preview |
github-actions bot
pushed a commit
that referenced
this pull request
Mar 9, 2026
…1078) In `BlockMap::sync`, blocks within an edited region are sorted and processed sequentially. Each block placement computes `rows_before_block` by subtracting `new_transforms.summary().input_rows` from the block's target position. The `Near`/`Below` cases have a guard that skips the block if the target is already behind the current progress, but `Above` and `Replace` were missing this guard. When a `Replace` block (tie_break 0) is processed before an `Above` block (tie_break 1) at the same or overlapping position, the `Replace` block consumes multiple input rows, advancing `input_rows` past the `Above` block's position. The subsequent `position - input_rows` subtraction underflows on `u32`, producing a huge `RowDelta` that wraps `wrap_row_end` past `wrap_row_start`, creating an inverted range that propagates through the display map layers and panics as `begin <= end (47 <= 0)` in a rope chunk slice. Add underflow guards to `Above` and `Replace`, matching the existing pattern in `Near`/`Below`. Release Notes: - Fixed a source of underflowing subtractions causing spurious panics
zed-zippy bot
added a commit
that referenced
this pull request
Mar 9, 2026
…1078) (cherry-pick to preview) (#51081) Cherry-pick of #51078 to preview ---- In `BlockMap::sync`, blocks within an edited region are sorted and processed sequentially. Each block placement computes `rows_before_block` by subtracting `new_transforms.summary().input_rows` from the block's target position. The `Near`/`Below` cases have a guard that skips the block if the target is already behind the current progress, but `Above` and `Replace` were missing this guard. When a `Replace` block (tie_break 0) is processed before an `Above` block (tie_break 1) at the same or overlapping position, the `Replace` block consumes multiple input rows, advancing `input_rows` past the `Above` block's position. The subsequent `position - input_rows` subtraction underflows on `u32`, producing a huge `RowDelta` that wraps `wrap_row_end` past `wrap_row_start`, creating an inverted range that propagates through the display map layers and panics as `begin <= end (47 <= 0)` in a rope chunk slice. Add underflow guards to `Above` and `Replace`, matching the existing pattern in `Near`/`Below`. Release Notes: - Fixed a source of underflowing subtractions causing spurious panics Co-authored-by: Lukas Wirth <[email protected]>
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.
In
BlockMap::sync, blocks within an edited region are sorted and processed sequentially. Each block placement computesrows_before_blockby subtractingnew_transforms.summary().input_rowsfrom the block's target position. TheNear/Belowcases have a guard that skips the block if the target is already behind the current progress, butAboveandReplacewere missing this guard.When a
Replaceblock (tie_break 0) is processed before anAboveblock (tie_break 1) at the same or overlapping position, theReplaceblock consumes multiple input rows, advancinginput_rowspast theAboveblock's position. The subsequentposition - input_rowssubtraction underflows onu32, producing a hugeRowDeltathat wrapswrap_row_endpastwrap_row_start, creating an inverted range that propagates through the display map layers and panics asbegin <= end (47 <= 0)in a rope chunk slice.Add underflow guards to
AboveandReplace, matching the existing pattern inNear/Below.Release Notes: