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

Panic: Byte range out of bounds #7615

Closed
stackotter opened this issue Jul 13, 2023 · 5 comments · Fixed by #7621
Closed

Panic: Byte range out of bounds #7615

stackotter opened this issue Jul 13, 2023 · 5 comments · Fixed by #7621
Labels
A-tree-sitter Area: Tree-sitter C-bug Category: This is a bug

Comments

@stackotter
Copy link

Summary

I get a panic while typing in a Svelte file (but only this specific svelte file, there must be some syntax combination I'm using in it that's causing the bug). It only started happening while I was writing out the uiSchemaFromSchema function (see reproduction section for code) and the first time it crashed was when I typed the value identifier in the for loop's of expression. Before that, Helix didn't have any issues with the file.

I've had a similar crash happen once or twice in the past, but usually weeks apart and each time in a different file.

Here's the backtrace:

> RUST_BACKTRACE=full hx .
thread 'main' panicked at 'byte_slice(): Byte range out of bounds: byte range 1107..1113, Rope/RopeSlice byte length 1112', /Users/brew/Library/Caches/Homebrew/cargo_cache/registry/src/github.com-1ecc6299db9ec823/ropey-1.6.0/src/slice.rs:703:23
stack backtrace:
   0:        0x100cee8ec - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf92d0b9100685592
   1:        0x10046c6a8 - core::fmt::write::hba950d59ddceeaaa
   2:        0x100cdd588 - std::io::Write::write_fmt::h9e52517f23e48360
   3:        0x100cee708 - std::sys_common::backtrace::print::hd205fa5e4b881c8b
   4:        0x100cde254 - std::panicking::default_hook::{{closure}}::h1fc0ab063b55fdaf
   5:        0x100cddf44 - std::panicking::default_hook::h68f99660ab2cf986
   6:        0x100cdeb28 - std::panicking::rust_panic_with_hook::haf8b9b224847163e
   7:        0x100cef4a0 - std::panicking::begin_panic_handler::{{closure}}::h71de5f2fd48a9ed8
   8:        0x100cee9dc - std::sys_common::backtrace::__rust_end_short_backtrace::h95cd4256776145cf
   9:        0x100cde6ac - _rust_begin_unwind
  10:        0x100da2f70 - core::panicking::panic_fmt::h03053be4fed319aa
  11:        0x1005d9870 - ropey::slice::RopeSlice::byte_slice::ha136e4972ae9ce0a
  12:        0x1005af134 - <helix_core::syntax::RopeProvider as tree_sitter::TextProvider>::text::hecb20d8635ad6e59
  13:        0x1005a10a4 - tree_sitter::QueryMatch::satisfies_text_predicates::h55008a0ce55697c9
  14:        0x1005a3810 - <tree_sitter::QueryCaptures<T> as core::iter::traits::iterator::Iterator>::next::h3a28fa798fe8b7fa
  15:        0x1005a6eac - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::h5411ac34d1f5251f
  16:        0x1005ed5b0 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::hfa5578df58a5a219
  17:        0x1005ae060 - helix_core::syntax::Syntax::highlight_iter::h646ce721ba39e95b
  18:        0x1008c9478 - helix_term::ui::editor::EditorView::doc_syntax_highlights::hcc03fe3ad64deb33
  19:        0x1008c8064 - helix_term::ui::editor::EditorView::render_view::h185cbf624a8263f0
  20:        0x1008d16ec - <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::render::hc9336957b3d2342d
  21:        0x100b13f04 - helix_term::application::Application::render::{{closure}}::h302495d62499de10
  22:        0x100b26f1c - tokio::runtime::park::CachedParkThread::block_on::h837eee16b9154c27
  23:        0x100b6fff4 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h90152830f3bb56e8
  24:        0x100b9c11c - tokio::runtime::runtime::Runtime::block_on::h38cf105e05fa28e5
  25:        0x100b89e4c - hx::main::hbd1d753432949e9f
  26:        0x100b67fd0 - std::sys_common::backtrace::__rust_begin_short_backtrace::h462d15e855494abc
  27:        0x100b56070 - std::rt::lang_start::{{closure}}::h15ead05c33eb1462
  28:        0x100cdcde8 - std::rt::lang_start_internal::hcf5249aa241f98ab
  29:        0x100b89f48 - _main

Reproduction Steps

I haven't figured out exactly what I'm doing that is causing the panic. But I can consistently get it when editing the following file. The panic just happens while typing and seems a bit random. Annoyingly, I've tried retyping stuff that made it panic and it didn't panic, but panicked later on while I was typing something new. The panic happens every minute or two (at the speed I'm typing at least) so it's pretty unworkable.

<script lang="ts">
    // Ignore the warning: this is actually used but svelte doesn't see it through the react preprocessor
    import Form from '@rjsf/core';
    import validator from '@rjsf/validator-ajv8';

    export let options: any;
    export let schema: any;

    let uiSchema = { 'ui:submitButtonOptions': { norender: true } };

    // Expects the schema to be a schema for an object.
    const uiSchemaFromSchema = (schema: any) => {
        var properties: any = {};
        for (let [key, value] of Object.entries(schema.properties)) {
            if ((value as any).type === 'string' && (value as any).multiline) {
                properties[key] = {
                    'ui:widget': 'textarea'
                };
            } else if ((value as any).type === 'object') {
                properties[key] = uiSchemaFromSchema(value);
            }
        }
    };

    const onOptionsChange = (event: any) => {
        options = event.formData;
    };

    // TODO: Figure out how to get form to update when the title of a property in the schema
    // changes. May be best off just rolling our own impl of a schema form for svelte.
</script>

<react:Form formData={options} {schema} {uiSchema} {validator} onChange={onOptionsChange} />

For completeness I've included my config.toml and languages.toml files.

theme = "nightfox"

[keys.normal]
"C-r" = [":reflow 80"]
"C-n" = [":reload"]
"C-h" = ["jump_view_left"]
"C-j" = ["jump_view_down"]
"C-k" = ["jump_view_up"]
"C-l" = ["jump_view_right"]

[keys.insert]
"C-f" = ["normal_mode"]

[keys.select]
"C-f" = ["normal_mode"]
"C-r" = [":reflow 80"]

[editor]
line-number = "relative"
mouse = true

[editor.cursor-shape]
insert = "bar"
normal = "block"
select = "underline"

[editor.file-picker]
hidden = false

[editor.whitespace.render]
tab = "all"
[[language]]
name = "swift"
auto-format = true
formatter = { command = "swift-format", args = ["format", "--configuration", ".swift-format"] }

[[language]]
name = "svelte"
auto-format = true

[[language]]
name = "typescript"
auto-format = true
formatter = { command = "prettier", args = ["--parser", "typescript"] }

[[language]]
name = "javascript"
auto-format = true
formatter = { command = "prettier", args = ["--parser", "babel"] }

[[language]]
name = "css"
auto-format = true
formatter = { command = "prettier", args = ["--parser", "css"] }

Helix log

~/.cache/helix/helix.log
2023-07-13T15:57:00.657 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:00.830 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":59,"line":10},"start":{"character":59,"line":10}},"text":"o"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":204}}}
2023-07-13T15:57:00.832 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:01.062 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":60,"line":10},"start":{"character":60,"line":10}},"text":"p"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":205}}}
2023-07-13T15:57:01.064 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:01.177 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":61,"line":10},"start":{"character":61,"line":10}},"text":"p"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":206}}}
2023-07-13T15:57:01.187 helix_vcs::diff::worker [INFO] Diff computation timed out, update of diffs might appear delayed
2023-07-13T15:57:01.191 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:01.410 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":62,"line":10},"start":{"character":62,"line":10}},"text":"o"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":207}}}
2023-07-13T15:57:01.412 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:01.643 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":63,"line":10},"start":{"character":63,"line":10}},"text":"s"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":208}}}
2023-07-13T15:57:01.645 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:01.690 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":64,"line":10},"start":{"character":64,"line":10}},"text":"e"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":209}}}
2023-07-13T15:57:01.692 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:01.868 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":65,"line":10},"start":{"character":65,"line":10}},"text":"d"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":210}}}
2023-07-13T15:57:01.870 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:02.059 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":66,"line":10},"start":{"character":66,"line":10}},"text":" "}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":211}}}
2023-07-13T15:57:02.062 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:02.458 helix_term::application [DEBUG] received editor event: IdleTimer
2023-07-13T15:57:02.462 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:02.723 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":67,"line":10},"start":{"character":67,"line":10}},"text":"t"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":212}}}
2023-07-13T15:57:02.725 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:02.808 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":68,"line":10},"start":{"character":68,"line":10}},"text":"o"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":213}}}
2023-07-13T15:57:02.809 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:02.888 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":69,"line":10},"start":{"character":69,"line":10}},"text":" "}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":214}}}
2023-07-13T15:57:02.890 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:03.287 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":70,"line":10},"start":{"character":70,"line":10}},"text":"a"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":215}}}
2023-07-13T15:57:03.289 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:03.366 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":71,"line":10},"start":{"character":71,"line":10}},"text":"n"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":216}}}
2023-07-13T15:57:03.368 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:03.478 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":72,"line":10},"start":{"character":72,"line":10}},"text":" "}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":217}}}
2023-07-13T15:57:03.480 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:03.680 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":73,"line":10},"start":{"character":73,"line":10}},"text":"a"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":218}}}
2023-07-13T15:57:03.682 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:03.869 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":74,"line":10},"start":{"character":74,"line":10}},"text":"r"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":219}}}
2023-07-13T15:57:03.871 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:04.032 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":75,"line":10},"start":{"character":75,"line":10}},"text":"r"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":220}}}
2023-07-13T15:57:04.034 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:04.089 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":76,"line":10},"start":{"character":76,"line":10}},"text":"a"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":221}}}
2023-07-13T15:57:04.090 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:04.199 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":77,"line":10},"start":{"character":77,"line":10}},"text":"y"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":222}}}
2023-07-13T15:57:04.201 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:04.295 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":78,"line":10},"start":{"character":78,"line":10}},"text":" "}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":223}}}
2023-07-13T15:57:04.297 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:04.694 helix_term::application [DEBUG] received editor event: IdleTimer
2023-07-13T15:57:04.698 helix_view::document [DEBUG] id 2 modified - last saved: 13, current: 13
2023-07-13T15:57:05.056 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":79,"line":10},"start":{"character":79,"line":10}},"text":"o"}],"textDocument":{"uri":"file:///Users/stackotter/Desktop/Projects/.../TemplateOptionsEditor.svelte","version":224}}}
2023-07-13T15:57:05.067 helix_vcs::diff::worker [INFO] Diff computation timed out, update of diffs might appear delayed

Platform

macOS

Terminal Emulator

kitty 0.28.1

Helix Version

helix 23.05 (7f5940b)

@stackotter stackotter added the C-bug Category: This is a bug label Jul 13, 2023
@archseer
Copy link
Member

Probably an upstream issue with the Svelte grammar, similar bug here #3283

@Snoupix
Copy link

Snoupix commented Jul 13, 2023

Potential duplicate with #7434 too, same kind of error and probably this one #7273 too but I may be wrong.

@pascalkuthe
Copy link
Member

pascalkuthe commented Jul 13, 2023

Potential duplicate with #7434 too, same kind of error and probably this one #7273 too but I may be wrong.

it doesn't look like those are related this seems like a grammar bug as @archseer said. You could try #7621 but I highly doubt that will fix this

@gabydd
Copy link
Member

gabydd commented Jul 14, 2023

I can reproduce this using that file by just adding a bunch of characters before the todo comment
minimal reproduction is open this file and put a bunch of spaces before the comment:

<script lang="ts">
    // TODO
</script>

(this is also actually fixed by pascal's pr)

@stackotter
Copy link
Author

Awesome, thanks for the fix @pascalkuthe! I've updated and so far I haven't gotten a crash, but it's hard to tell without spending much time using it. I'll reopen if it happens again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tree-sitter Area: Tree-sitter C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants