Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when using surround_replace/delete #9796

Merged
merged 1 commit into from Mar 3, 2024

Conversation

trink
Copy link
Contributor

@trink trink commented Mar 3, 2024

  1. Create a document containing {A}
  2. C-w v # vsplit
  3. gl # goto_line_end
  4. b # move_prev_word_start
  5. ` # switch_to_lowercase
  6. mrm( # surround replace
  7. C-w v # vsplit

In the debug build surround_replace/delete will immedately assert with assertion failed: last <= from', transaction.rs:597:13. The splits and lowercase conversion are not needed to trigger the bug.

In the release build the surround becomes )a( and the last vsplit causes the transaction to panic.
internal error: entered unreachable code: (Some(Retain(18446744073709551573)))', transaction.rs:185:46

Since the selection direction is backwards get_surround_pos returns the pairs reversed but the downstream code assumes they are in the forward direction.

1. Create a document containing `{A}`
1. C-w v # vsplit
1. gl    # goto_line_end
1. b     # move_prev_word_start
1. `     # switch_to_lowercase
1. mrm(  # surround replace
1. C-w v # vsplit

In the debug build surround_replace/delete will immedately assert with
`assertion failed: last <= from', transaction.rs:597:13`. The splits and
lowercase conversion are not needed to trigger the bug.

In the release build the surround becomes `)a(` and the last vsplit
causes the transaction to panic.
`internal error: entered unreachable code:
(Some(Retain(18446744073709551573)))', transaction.rs:185:46`

Since the selection direction is backwards get_surround_pos returns the
pairs reversed but the downstream code assumes they are in the forward
direction.
@the-mikedavis the-mikedavis added C-bug Category: This is a bug S-waiting-on-review Status: Awaiting review from a maintainer. A-command Area: Commands labels Mar 3, 2024
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find, thanks!

@pascalkuthe pascalkuthe merged commit 9267343 into helix-editor:master Mar 3, 2024
6 checks passed
@trink trink deleted the surround_replace branch March 3, 2024 17:58
@trink trink restored the surround_replace branch March 3, 2024 17:59
@woojiq
Copy link
Contributor

woojiq commented Mar 3, 2024

This probably fixes #6626, but I haven't checked.

@pascalkuthe
Copy link
Member

Good catch. I meant to close that issue anyway since it doesn't have a reproduction case

@pascalkuthe pascalkuthe mentioned this pull request Mar 3, 2024
Desdaemon pushed a commit to Desdaemon/helix that referenced this pull request Mar 4, 2024
1. Create a document containing `{A}`
1. C-w v # vsplit
1. gl    # goto_line_end
1. b     # move_prev_word_start
1. `     # switch_to_lowercase
1. mrm(  # surround replace
1. C-w v # vsplit

In the debug build surround_replace/delete will immedately assert with
`assertion failed: last <= from', transaction.rs:597:13`. The splits and
lowercase conversion are not needed to trigger the bug.

In the release build the surround becomes `)a(` and the last vsplit
causes the transaction to panic.
`internal error: entered unreachable code:
(Some(Retain(18446744073709551573)))', transaction.rs:185:46`

Since the selection direction is backwards get_surround_pos returns the
pairs reversed but the downstream code assumes they are in the forward
direction.
@trink trink deleted the surround_replace branch March 4, 2024 17:19
shortc pushed a commit to shortc/helix that referenced this pull request Mar 31, 2024
1. Create a document containing `{A}`
1. C-w v # vsplit
1. gl    # goto_line_end
1. b     # move_prev_word_start
1. `     # switch_to_lowercase
1. mrm(  # surround replace
1. C-w v # vsplit

In the debug build surround_replace/delete will immedately assert with
`assertion failed: last <= from', transaction.rs:597:13`. The splits and
lowercase conversion are not needed to trigger the bug.

In the release build the surround becomes `)a(` and the last vsplit
causes the transaction to panic.
`internal error: entered unreachable code:
(Some(Retain(18446744073709551573)))', transaction.rs:185:46`

Since the selection direction is backwards get_surround_pos returns the
pairs reversed but the downstream code assumes they are in the forward
direction.
postsolar pushed a commit to postsolar/helix that referenced this pull request Apr 4, 2024
1. Create a document containing `{A}`
1. C-w v # vsplit
1. gl    # goto_line_end
1. b     # move_prev_word_start
1. `     # switch_to_lowercase
1. mrm(  # surround replace
1. C-w v # vsplit

In the debug build surround_replace/delete will immedately assert with
`assertion failed: last <= from', transaction.rs:597:13`. The splits and
lowercase conversion are not needed to trigger the bug.

In the release build the surround becomes `)a(` and the last vsplit
causes the transaction to panic.
`internal error: entered unreachable code:
(Some(Retain(18446744073709551573)))', transaction.rs:185:46`

Since the selection direction is backwards get_surround_pos returns the
pairs reversed but the downstream code assumes they are in the forward
direction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-command Area: Commands C-bug Category: This is a bug S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants