Fix crash: vim paste panics on editor-copied entire-line selections#49134
Merged
Fix crash: vim paste panics on editor-copied entire-line selections#49134
Conversation
The editor's copy/cut skips the newline separator between entire-line clipboard selections (since the text already ends with newline), but vim's paste unconditionally assumed a newline separator by always adding +1 to start_offset. This caused out-of-bounds string indexing when pasting clipboard data produced by the editor's copy with multiple entire-line selections.
d856571 to
8ad1bc0
Compare
3 tasks
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.
When clipboard data was produced by the editor's copy/cut with multiple entire-line selections, vim's paste would panic with
byte index N is out of bounds.The editor's
do_copyandcut_commonskip the\nseparator between clipboard selections when the previous selection was an entire-line selection (because the text already ends with\n). However, vim's paste code unconditionally didstart_offset = end_offset + 1, always assuming a\nseparator exists between every pair of selections. This caused the accumulated offset to exceed the text length, resulting in a string slicing panic.The fix checks
clipboard_selection.is_entire_lineto decide whether to skip the separator, matching the behavior of the editor's owndo_pastemethod. The same fix is applied to both the vim and helix paste implementations.Release Notes: