Skip to content

Merging two syntax sets panics #574

@jyn514

Description

@jyn514

I wrote this code:

let mut merged_syntaxes = SYNTAX_SET.clone().into_builder();
for extra in extra_syntaxes.clone().into_builder().syntaxes() {
    merged_syntaxes.add(extra.clone());
}

I expect it to run without panicking; the whole point of into_builder() is that it removes the SyntaxSet-specific relative indexes. instead, i get this panic:

thread '<unnamed>' panicked at /home/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syntect-5.2.0/src/parsing/syntax_set.rs:683:62:
index out of bounds: the len is 78 but the index is 129
stack backtrace:
   0: rust_begin_unwind
             at /rustc/f7cc13af822fe68c64fec0b05aa9dd1412451f7c/library/std/src/panicking.rs:695:5
...
   5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
             at /home/jyn/.local/lib/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3359:9
   6: syntect::parsing::syntax_set::SyntaxSetBuilder::recursively_mark_no_prototype
             at /home/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syntect-5.2.0/src/parsing/syntax_set.rs:683:62
   7: syntect::parsing::syntax_set::SyntaxSetBuilder::recursively_mark_no_prototype
             at /home/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syntect-5.2.0/src/parsing/syntax_set.rs:717:29
   8: syntect::parsing::syntax_set::SyntaxSetBuilder::build
             at /home/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syntect-5.2.0/src/parsing/syntax_set.rs:598:17
   9: config::highlighting::resolve_syntax_and_theme::{{closure}}
             at /home/jyn/src/zola/components/config/src/highlighting.rs:53:21
...

that points at https://github.com/trishume/syntect/blob/v5.2.0/src/parsing/syntax_set.rs#L683. i suspect that context_id is not being renumbered correctly when calling into_builder().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions