Skip to content

helix: Fix paste crash#58373

Merged
MartinYe1234 merged 1 commit into
mainfrom
fix-modal-editor-paste-crash
Jun 3, 2026
Merged

helix: Fix paste crash#58373
MartinYe1234 merged 1 commit into
mainfrom
fix-modal-editor-paste-crash

Conversation

@Anthony-Eid

@Anthony-Eid Anthony-Eid commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Closes #58343

This crash happened because Helix paste restored selection using the raw clipboard text length, but buffer edits normalize CRLF line endings to LF before inserting. When pasting CRLF text at or near EOF, the restored selection could extend past the normalized snapshot length and panic in MutableSelectionsCollection::select_ranges. The fix normalizes the text before measuring it for selection restoration and adds regression coverage for CRLF paste in Helix mode.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed a crash that could occur when pasting at the end of a file in Helix mode

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 3, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Jun 3, 2026
@zed-industries-bot

Copy link
Copy Markdown
Contributor
Messages
📖

This PR includes links to the following GitHub Issues: #58343
If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by 🚫 dangerJS against 117914a

@MartinYe1234 MartinYe1234 added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit 1125a45 Jun 3, 2026
48 checks passed
@MartinYe1234 MartinYe1234 deleted the fix-modal-editor-paste-crash branch June 3, 2026 03:48
dandv pushed a commit to dandv/zed that referenced this pull request Jun 3, 2026
Closes [zed-industries#58343](<zed-industries#58343>)

This crash happened because Helix paste restored selection using the raw
clipboard text length, but buffer edits normalize CRLF line endings to
LF before inserting. When pasting CRLF text at or near EOF, the restored
selection could extend past the normalized snapshot length and panic in
`MutableSelectionsCollection::select_ranges`. The fix normalizes the
text before measuring it for selection restoration and adds regression
coverage for CRLF paste in Helix mode.

Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content is consistent with the [UI/UX
checklist](<https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist>)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash that could occur when pasting at the end of a file in
Helix mode
@Anthony-Eid

Copy link
Copy Markdown
Contributor Author

/cherry-pick preview

zed-zippy Bot added a commit that referenced this pull request Jun 3, 2026
Cherry-pick of #58373 to preview

----
Closes [#58343](<#58343>)

This crash happened because Helix paste restored selection using the raw
clipboard text length, but buffer edits normalize CRLF line endings to
LF before inserting. When pasting CRLF text at or near EOF, the restored
selection could extend past the normalized snapshot length and panic in
`MutableSelectionsCollection::select_ranges`. The fix normalizes the
text before measuring it for selection restoration and adds regression
coverage for CRLF paste in Helix mode.

Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content is consistent with the [UI/UX

checklist](<https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist>)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash that could occur when pasting at the end of a file in
Helix mode

Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 8, 2026
Closes [zed-industries#58343](<zed-industries#58343>)

This crash happened because Helix paste restored selection using the raw
clipboard text length, but buffer edits normalize CRLF line endings to
LF before inserting. When pasting CRLF text at or near EOF, the restored
selection could extend past the normalized snapshot length and panic in
`MutableSelectionsCollection::select_ranges`. The fix normalizes the
text before measuring it for selection restoration and adds regression
coverage for CRLF paste in Helix mode.

Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content is consistent with the [UI/UX
checklist](<https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist>)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash that could occur when pasting at the end of a file in
Helix mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zed has started crashing since v1.4.4

3 participants