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 in trim_first_and_last_line_of_whitespace #727

Closed
mykter opened this issue Feb 25, 2021 · 0 comments · Fixed by #865
Closed

panic in trim_first_and_last_line_of_whitespace #727

mykter opened this issue Feb 25, 2021 · 0 comments · Fixed by #865

Comments

@mykter
Copy link
Contributor

mykter commented Feb 25, 2021

Given a Vue <script> with a carriage return (and no linefeed), followed by non-whitespace, followed by whitespace, we try and return a slice that ends before it starts.

It seems likely the logic around line 43 (which is looking for carriage returns specifically) is at fault.

$ echo -e '<script>\ra </script>'  > test.vue
$ RUST_BACKTRACE=1 ./target/debug/tokei ./test.vue
thread '<unnamed>' panicked at 'slice index starts at 2 but ends at 1', src/utils/ext.rs:55:10
stack backtrace:
   0: rust_begin_unwind
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:92:14
   2: core::slice::index::slice_index_order_fail
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/slice/index.rs:48:5
   3: <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index
             at /home/mmacnair/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/index.rs:236:13
   4: <core::ops::range::RangeInclusive<usize> as core::slice::index::SliceIndex<[T]>>::index
             at /home/mmacnair/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/index.rs:404:9
   5: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /home/mmacnair/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/index.rs:15:9
   6: <[u8] as tokei::utils::ext::SliceExt>::trim_first_and_last_line_of_whitespace
             at ./src/utils/ext.rs:55:10
   7: tokei::language::syntax::SyntaxCounter::parse_context
             at ./src/language/syntax.rs:471:25
   8: tokei::language::syntax::SyntaxCounter::perform_multi_line_analysis
             at ./src/language/syntax.rs:245:34
   9: tokei::language::language_type::LanguageType::parse_lines
             at ./src/language/language_type.rs:154:23
  10: tokei::language::language_type::LanguageType::parse_from_slice
             at ./src/language/language_type.rs:119:13

Found through fuzzing after around 80 million test cases. See #726.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant