helix icon indicating copy to clipboard operation
helix copied to clipboard

Helix crashes after inputing emojies.

Open mkblast opened this issue 1 year ago • 9 comments

Summary

The editor crashes after adding emojies, I don't have much information so ill add a video and the full backtrace.

Screencast from 2023-04-07 16-34-05.webm

Rust Backtrace

thread 'main' panicked at 'byte index 46 is not a char boundary; it is inside '😆' (bytes 45..49) of `#include <stdio.h>

int main() {
    printf("😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆`[...]', /builddir/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-segmentation-1.10.1/src/grapheme.rs:553:22
stack backtrace:
   0:     0x55c0267dd42e - <unknown>
   1:     0x55c025e4aaee - <unknown>
   2:     0x55c0267d7605 - <unknown>
   3:     0x55c0267dd205 - <unknown>
   4:     0x55c0267df00f - <unknown>
   5:     0x55c0267ded84 - <unknown>
   6:     0x55c0267df6b1 - <unknown>
   7:     0x55c0267df446 - <unknown>
   8:     0x55c0267dd95c - <unknown>
   9:     0x55c0267df182 - <unknown>
  10:     0x55c025dadeb3 - <unknown>
  11:     0x55c025e4eff9 - <unknown>
  12:     0x55c025dae517 - <unknown>
  13:     0x55c025f8deb6 - <unknown>
  14:     0x55c025f96586 - <unknown>
  15:     0x55c0262e8586 - <unknown>
  16:     0x55c02640adb3 - <unknown>
  17:     0x55c0263308c3 - <unknown>
  18:     0x55c026331344 - <unknown>
  19:     0x55c026334113 - <unknown>
  20:     0x55c02633e951 - <unknown>
  21:     0x55c02662c9b3 - <unknown>
  22:     0x55c02664402d - <unknown>
  23:     0x55c026640578 - <unknown>
  24:     0x55c02665b30d - <unknown>
  25:     0x55c02666f0fc - <unknown>
  26:     0x55c026699bbf - <unknown>
  27:     0x55c026647d03 - <unknown>
  28:     0x55c026664d6d - <unknown>
  29:     0x55c0267d2028 - <unknown>
  30:     0x55c02669dd25 - <unknown>
  31:     0x7f6a38205510 - __libc_start_call_main
  32:     0x7f6a382055c9 - __libc_start_main@GLIBC_2.2.5
  33:     0x55c025df3305 - <unknown>
  34:                0x0 - <unknown>

~/.cache/helix/helix.log
2023-04-07T16:40:58.821 helix_vcs [ERROR] Error {
    context: "failed to open git repo",
    source: Discover(
        NoGitRepositoryWithinFs {
            path: "/home/karim/Documents/Projects/code/c",
            limit: "/",
        },
    ),
}
2023-04-07T16:40:58.821 helix_vcs [ERROR] failed to open diff base for /home/karim/Documents/Projects/code/c/emoji.c
2023-04-07T16:40:58.822 helix_vcs [ERROR] Error {
    context: "failed to open git repo",
    source: Discover(
        NoGitRepositoryWithinFs {
            path: "/home/karim/Documents/Projects/code/c",
            limit: "/",
        },
    ),
}
2023-04-07T16:40:58.822 helix_vcs [ERROR] failed to obtain current head name for /home/karim/Documents/Projects/code/c/emoji.c
2023-04-07T16:40:58.822 helix_view::editor [ERROR] Failed to initialize the LSP for `source.c` { cannot find binary path }

Platform

Linux

Terminal Emulator

gnome-console

Helix Version

helix 23.03

mkblast avatar Apr 07 '23 15:04 mkblast

I was able to reproduce this. However, it seems like this is not an issue in helix, but rather in the unicode_segmentation crate, possibly covered by this issue

KMikeeU avatar Apr 07 '23 18:04 KMikeeU

Backtrace in debug mode...
thread 'main' panicked at 'byte index 44 is not a char boundary; it is inside '😆' (bytes 43..47) of `#include <stdio.h>

int main() {
  printf("😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆`[...]', /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-segmentation-1.10.1/src/grapheme.rs:553:22
stack backtrace:
   0: rust_begin_unwind
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/str/mod.rs:86:9
   4: core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::RangeFrom<usize>>::index
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/str/traits.rs:370:21
   5: core::str::traits::<impl core::ops::index::Index<I> for str>::index
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/str/traits.rs:65:9
   6: unicode_segmentation::grapheme::GraphemeCursor::is_boundary
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-segmentation-1.10.1/src/grapheme.rs:553:22
   7: helix_core::graphemes::is_grapheme_boundary_byte
             at ./helix-core/src/graphemes.rs:340:15
   8: helix_core::graphemes::ensure_grapheme_boundary_next_byte
             at ./helix-core/src/graphemes.rs:290:12
   9: helix_term::ui::editor::EditorView::doc_syntax_highlights::{{closure}}
             at ./helix-term/src/ui/editor.rs:310:51
  10: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:306:13
  11: core::option::Option<T>::map
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/option.rs:929:29
  12: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/iter/adapters/map.rs:103:9
  13: <alloc::boxed::Box<I,A> as core::iter::traits::iterator::Iterator>::next
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/alloc/src/boxed.rs:1874:9
  14: <helix_core::syntax::Merge<I> as core::iter::traits::iterator::Iterator>::next
             at ./helix-core/src/syntax.rs:2145:35
  15: <alloc::boxed::Box<I,A> as core::iter::traits::iterator::Iterator>::next
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/alloc/src/boxed.rs:1874:9
  16: <helix_term::ui::document::StyleIter<H> as core::iter::traits::iterator::Iterator>::next
             at ./helix-term/src/ui/document.rs:49:33
  17: helix_term::ui::document::render_text
             at ./helix-term/src/ui/document.rs:264:26
  18: helix_term::ui::document::render_document
             at ./helix-term/src/ui/document.rs:106:5
  19: helix_term::ui::editor::EditorView::render_view
             at ./helix-term/src/ui/editor.rs:185:9
  20: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::render
             at ./helix-term/src/ui/editor.rs:1387:13
  21: helix_term::compositor::Compositor::render
             at ./helix-term/src/compositor.rs:170:13
  22: helix_term::application::Application::render::{{closure}}
             at ./helix-term/src/application.rs:282:9
  23: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/future/mod.rs:91:19
  24: helix_term::application::Application::handle_terminal_events::{{closure}}
             at ./helix-term/src/application.rs:639:26
  25: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/future/mod.rs:91:19
  26: helix_term::application::Application::event_loop_until_idle::{{closure}}
             at ./helix-term/src/application.rs:323:55
  27: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/future/mod.rs:91:19
  28: helix_term::application::Application::event_loop::{{closure}}
             at ./helix-term/src/application.rs:299:57
  29: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/future/mod.rs:91:19
  30: helix_term::application::Application::run::{{closure}}
             at ./helix-term/src/application.rs:1108:38
  31: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/future/mod.rs:91:19
  32: hx::main_impl::{{closure}}
             at ./helix-term/src/main.rs:157:53
  33: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/future/mod.rs:91:19
  34: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/park.rs:283:63
  35: tokio::runtime::coop::with_budget
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/coop.rs:107:5
  36: tokio::runtime::coop::budget
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/coop.rs:73:5
  37: tokio::runtime::park::CachedParkThread::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/park.rs:283:31
  38: tokio::runtime::context::BlockingRegionGuard::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/context.rs:315:13
  39: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/scheduler/multi_thread/mod.rs:66:9
  40: tokio::runtime::runtime::Runtime::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/runtime.rs:304:45
  41: hx::main_impl
             at ./helix-term/src/main.rs:159:5
  42: hx::main
             at ./helix-term/src/main.rs:38:21
  43: core::ops::function::FnOnce::call_once
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

on 3dd715a115880831e3a0f75a3c00f0b6e1a8364f

the-mikedavis avatar Apr 07 '23 18:04 the-mikedavis

Having another look at this, I think the issue is that the unicode_segmentation crate expects indices into slices to be at the start of unicode sequences, this is something that could be checked in helix before calling the crate's functions.

Edit: I created a branch to try and understand/fix this issue, however I am not very familiar with the helix codebase and the solution feels very "hacky". Should I still open a PR for feedback?

KMikeeU avatar Apr 08 '23 12:04 KMikeeU

This check won't be included in the unicode-segmentation crate (for now), see https://github.com/unicode-rs/unicode-segmentation/issues/120

KMikeeU avatar Apr 11 '23 18:04 KMikeeU

This issue was happening with me using both kitty and wezterm. Something similar also happens in wezterm using font ligatures.

wuerges avatar Apr 20 '23 12:04 wuerges

I also hit this while running the digraphs patch.

omentic avatar Jul 16 '23 20:07 omentic

I am not sure but this might have been fixed by https://github.com/helix-editor/helix/pull/7417 could you try on master and see if you this crash still happens?

gabydd avatar Jul 16 '23 22:07 gabydd

I haven't been able to reproduce it unfortunately, I just got a traceback of the same panic pointing to src/grapheme.rs:553:22.

The digraph patch was on top of master and the crash occured while mucking about with entering and copying and pasting unicode characters using insert_digraph while in a TOML file. I don't understand #7417 enough to know if that means there's liable to be a bug still in master, or in the patch, or in the TOML language server...

omentic avatar Jul 16 '23 23:07 omentic

Another data point in case it's helpful, I'm able to get Helix @master to panic with these steps: Environment: Ubuntu, Wayland, Alacritty, Zellij

  • Start Helix
  • In a scratch buffer, paste this code (with Ctrl+Shift+V):
int main() {
  printf("😆");
}
  • :set-language c
  • move the cursor to the emoji (😆)
  • Yank (y) and hold p (paste after selection) and soon enough I get the crash.
Stacktrace
helix on  master [$…] is 📦 v23.10.0 via 🦀 v1.70.0 direnv loaded/denied
❯ env RUST_BACKTRACE=1 cargo run -- -vv
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/hx -vv`
thread 'main' panicked at 'byte index 24 is not a char boundary; it is inside '😆' (bytes 23..27) of `int main() {
  printf("😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆😆`[...]', /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-seg
stack backtrace:
pp   0: rust_begin_unwind
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/str/mod.rs:86:9
   4: core::str::traits:: for core::ops::range::RangeFrom>::index
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/str/traits.rs:382:21
   5: core::str::traits:: for str>::index
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/str/traits.rs:62:9
   6: unicode_segmentation::grapheme::GraphemeCursor::is_boundary
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-segmentation-1.11.0/src/grapheme.rs:553:22
   7: helix_core::graphemes::is_grapheme_boundary_byte
             at ./helix-core/src/graphemes.rs:340:15
   8: helix_core::graphemes::ensure_grapheme_boundary_next_byte
             at ./helix-core/src/graphemes.rs:290:12
   9: helix_term::ui::editor::EditorView::doc_syntax_highlights::{{closure}}
             at ./helix-term/src/ui/editor.rs:326:51
  10: core::ops::function::impls:: for &mut F>::call_once
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:310:13
  11: core::option::Option::map
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/option.rs:1099:29
  12: <:iter::adapters::map::map> as core::iter::traits::iterator::Iterator>::next
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/iter/adapters/map.rs:103:9
  13: <:boxed::box> as core::iter::traits::iterator::Iterator>::next
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1907:9
  14: <:ui::document::styleiter> as core::iter::traits::iterator::Iterator>::next
             at ./helix-term/src/ui/document.rs:49:33
  15: helix_term::ui::document::render_text
             at ./helix-term/src/ui/document.rs:283:33
  16: helix_term::ui::document::render_document
             at ./helix-term/src/ui/document.rs:107:5
  17: helix_term::ui::editor::EditorView::render_view
             at ./helix-term/src/ui/editor.rs:197:9
  18: <:ui::editor::editorview as helix_term::compositor::component>::render
             at ./helix-term/src/ui/editor.rs:1450:13
  19: helix_term::compositor::Compositor::render
             at ./helix-term/src/compositor.rs:178:13
  20: helix_term::application::Application::render::{{closure}}
             at ./helix-term/src/application.rs:278:9
  21: helix_term::application::Application::handle_terminal_events::{{closure}}
             at ./helix-term/src/application.rs:651:26
  22: helix_term::application::Application::event_loop_until_idle::{{closure}}
             at ./helix-term/src/application.rs:320:55
  23: helix_term::application::Application::event_loop::{{closure}}
             at ./helix-term/src/application.rs:294:57
  24: helix_term::application::Application::run::{{closure}}
             at ./helix-term/src/application.rs:1199:38
  25: hx::main_impl::{{closure}}
             at ./helix-term/src/main.rs:161:53
  26: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:63
  27: tokio::runtime::coop::with_budget
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:107:5
  28: tokio::runtime::coop::budget
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:73:5
  29: tokio::runtime::park::CachedParkThread::block_on
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:31
  30: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/blocking.rs:66:9
  31: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  32: tokio::runtime::context::runtime::enter_runtime
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/runtime.rs:65:16
  33: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  34: tokio::runtime::runtime::Runtime::block_on
             at /home/mandx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/runtime.rs:350:45
  35: hx::main_impl
             at ./helix-term/src/main.rs:163:5
  36: hx::main
             at ./helix-term/src/main.rs:37:21
  37: core::ops::function::FnOnce::call_once
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

helix.log

Here's the interesting part, I don't get a panic if I don't change the syntax (that is, leave it as language text).

mandx avatar Mar 22 '24 22:03 mandx