Skip to content

editor: Fix underflow panic in block map sync when blocks overlap (#51078) (cherry-pick to preview)#51081

Merged
zed-zippy[bot] merged 1 commit intov0.227.xfrom
cherry-pick-v0.227.x-8d5689a7
Mar 9, 2026
Merged

editor: Fix underflow panic in block map sync when blocks overlap (#51078) (cherry-pick to preview)#51081
zed-zippy[bot] merged 1 commit intov0.227.xfrom
cherry-pick-v0.227.x-8d5689a7

Conversation

@zed-zippy
Copy link
Copy Markdown
Contributor

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

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

…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
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 9, 2026
@zed-community-bot zed-community-bot bot added the bot Pull requests authored by a bot label Mar 9, 2026
@zed-zippy zed-zippy bot merged commit 823578b into v0.227.x Mar 9, 2026
38 checks passed
@zed-zippy zed-zippy bot deleted the cherry-pick-v0.227.x-8d5689a7 branch March 9, 2026 08:55
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