drahnr / cargo-spellcheck

Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Segmentation fault when running cargo spellcheck

surban opened this issue · comments

Describe the bug

Segmentation fault, without further message.

To Reproduce

Run cargo spellcheck.

Version is 0.8.14.
Cargo version is 1.55.0.

Expected behavior

It does something nice :)

Screenshots

Backtracke obtained by gdb:

surban@dino:~/dev/remoc/remoc$ gdb --args cargo spellcheck 
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from cargo...
(gdb) go
Command requires an argument.
(gdb) run
Starting program: /home/surban/.cargo/bin/cargo spellcheck
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
process 15661 is executing new program: /home/surban/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
process 15661 is executing new program: /home/surban/.cargo/bin/cargo-spellcheck
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/surban/.cargo/bin/cargo-spellcheck.
Use `info auto-load python-scripts [REGEXP]' to list them.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7a45700 (LWP 15665)]
[New Thread 0x7ffff7844700 (LWP 15666)]
[New Thread 0x7ffff7643700 (LWP 15667)]
[New Thread 0x7ffff7442700 (LWP 15668)]
[New Thread 0x7ffff7241700 (LWP 15669)]
[New Thread 0x7ffff7040700 (LWP 15670)]
[New Thread 0x7ffff6e3f700 (LWP 15671)]
[New Thread 0x7ffff6c3e700 (LWP 15672)]
[New Thread 0x7ffff6a37700 (LWP 15673)]
[New Thread 0x7ffff6833700 (LWP 15674)]
[New Thread 0x7ffff662f700 (LWP 15675)]
[New Thread 0x7ffff642b700 (LWP 15676)]
[New Thread 0x7ffff622a700 (LWP 15677)]
[New Thread 0x7ffff6026700 (LWP 15678)]
[New Thread 0x7ffff5e1f700 (LWP 15679)]
[New Thread 0x7ffff5c1e700 (LWP 15680)]
[New Thread 0x7ffff5a17700 (LWP 15681)]

Thread 11 "cargo-spellchec" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6833700 (LWP 15674)]
0x000055555594f76b in mkallsmall (s="bioreactor", csconv=0x0) at vendor/src/hunspell/csutil.cxx:536
536         *aI = clower(csconv, static_cast<unsigned char>(*aI));
(gdb) bt
#0  0x000055555594f76b in mkallsmall (s="bioreactor", csconv=0x0) at vendor/src/hunspell/csutil.cxx:536
#1  0x0000555555931d3d in SuggestMgr::ngsuggest (this=0x5555591e76c0, 
    wlst=std::vector of length 0, capacity 0, w=<optimized out>, 
    rHMgr=std::vector of length 2, capacity 2 = {...}, captype=captype@entry=0)
    at vendor/src/hunspell/suggestmgr.cxx:1206
#2  0x00005555559267a5 in HunspellImpl::suggest_internal (this=0x5555591e82c0, word=..., 
    capwords=<optimized out>, abbv=<optimized out>, captype=@0x7ffff68311b4: 0)
    at /usr/include/c++/9/bits/basic_string.h:2300
#3  0x0000555555927e41 in HunspellImpl::suggest (this=0x5555591e82c0, word="serializable")
    at vendor/src/hunspell/hunspell.cxx:899
#4  0x0000555555928674 in HunspellImpl::suggest (this=0x5555591e82c0, slst=0x7ffff68312f8, 
    word=0x7fffc8406b80 "serializable") at /usr/include/c++/9/bits/char_traits.h:300
#5  0x000055555591aedb in hunspell_rs::Hunspell::suggest (self=0x55555b5a9ea0, word=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/hunspell-rs-0.3.0/src/lib.rs:91
#6  0x000055555574ac1e in cargo_spellcheck::checker::hunspell::obtain_suggestions (
    plain=0x7ffff68318e8, chunk=0x555557181b00, hunspell=0x55555b5a9ea0, origin=0x55555722dcf8, 
    word=..., range=..., allow_concatenated=<optimized out>, allow_dashed=<optimized out>, 
    allow_emojis=<optimized out>, acc=0x7ffff6831950)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-spellcheck-0.8.14/src/checker/hunspell.rs:362
#7  0x00005555556d2129 in <cargo_spellcheck::checker::hunspell::HunspellChecker as cargo_spellcheck::checker::Checker>::check::{{closure}} (acc=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-spellcheck-0.8.14/src/checker/hunspell.rs:281
#8  <rayon::iter::try_fold::TryFoldFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume (
    self=..., item=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/try_fold.rs:147
#9  rayon::iter::plumbing::Folder::consume_iter (self=..., iter=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:179
#10 0x000055555578a52e in <rayon::iter::map::MapFolder<C,F> as rayon::iter::plumbing::Folder<T>>::consume_iter (self=..., iter=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/map.rs:248
#11 rayon::iter::plumbing::Producer::fold_with (self=..., folder=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:110
#12 rayon::iter::plumbing::bridge_producer_consumer::helper (len=<optimized out>, 
    migrated=<optimized out>, splitter=..., producer=..., consumer=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:438
#13 0x0000555555700712 in rayon::iter::plumbing::bridge_producer_consumer::helper::{{closure}} (
    context=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:427
#14 rayon_core::join::join_context::call_b::{{closure}} (migrated=<optimized out>)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:129
#15 rayon_core::job::StackJob<L,F,R>::run_inline (self=..., stolen=<optimized out>)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:97
#16 0x000055555575e4d0 in rayon_core::join::join_context::{{closure}} (worker_thread=0x7ffff6832800, 
    injected=<optimized out>)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:158
#17 0x000055555578a6af in rayon_core::registry::in_worker (op=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:875
#18 rayon_core::join::join_context (oper_a=..., oper_b=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:132
#19 rayon::iter::plumbing::bridge_producer_consumer::helper (len=<optimized out>, 
    migrated=<optimized out>, splitter=..., producer=..., consumer=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:416
#20 0x000055555570b9c1 in rayon::iter::plumbing::bridge_producer_consumer::helper::{{closure}} (
    context=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.5.1/src/iter/plumbing/mod.rs:427
#21 rayon_core::join::join_context::call_b::{{closure}} (migrated=true)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:129
#22 <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::call::{{closure}} ()
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:113
#23 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once (self=..., 
    _args=<optimized out>)
    at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:347
#24 std::panicking::try::do_call (data=<optimized out>)
    at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:401
#25 std::panicking::try (f=...)
    at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:365
#26 std::panic::catch_unwind (f=...)
    at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:434
#27 rayon_core::unwind::halt_unwinding (func=...)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17
#28 <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute (this=0x7ffff723ffa0)
    at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:119
--Type <RET> for more, q to quit, c to continue without paging--c
#29 0x0000555555614a21 in rayon_core::job::JobRef::execute (self=<optimized out>) at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:59
#30 rayon_core::registry::WorkerThread::execute (self=<optimized out>, job=...) at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:749
#31 rayon_core::registry::WorkerThread::wait_until_cold (self=<optimized out>, latch=<optimized out>) at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:726
#32 0x0000555555a3529d in rayon_core::registry::WorkerThread::wait_until (self=0x7ffff6832800, latch=<optimized out>) at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:700
#33 rayon_core::registry::main_loop (registry=..., index=9, worker=...) at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:833
#34 rayon_core::registry::ThreadBuilder::run (self=...) at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:55
#35 0x0000555555a36b65 in <rayon_core::registry::DefaultSpawn as rayon_core::registry::ThreadSpawn>::spawn::{{closure}} () at /home/surban/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:100
#36 std::sys_common::backtrace::__rust_begin_short_backtrace (f=...) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:125
#37 0x0000555555a32d5b in std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} () at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/thread/mod.rs:476
#38 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once (self=..., _args=<optimized out>) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:347
#39 std::panicking::try::do_call (data=<optimized out>) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:401
#40 std::panicking::try (f=...) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:365
#41 std::panic::catch_unwind (f=...) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:434
#42 std::thread::Builder::spawn_unchecked::{{closure}} () at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/thread/mod.rs:475
#43 core::ops::function::FnOnce::call_once{{vtable-shim}} () at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:227
#44 0x0000555555ab6357 in <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/boxed.rs:1572
#45 <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/boxed.rs:1572
#46 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:74
#47 0x00007ffff7d9b609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#48 0x00007ffff7b6d293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Yeah, this the worst case. This is a bug in hunspell or how it's used, not sure.

Could you share the codebase you ran it on?

Could you provide the output of:

pkg-config --modversion or the version that you get out of your pkg manager?

I have 1.7.0 and I tried to run it on a checkout of remoc at commit c9f6223e6b2de156ab31de167b6d743d1a0c2ddb and it (v0.8.14) works fine:

error: spellcheck(Hunspell)
   --> /tmp/remoc/remoc/src/chmux/cfg.rs:27
    |
 27 |  This must not exceed 2^31 = 2147483648.
    |                       ^^^^
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/remoc/src/chmux/cfg.rs:27
    |
 27 |  This must not exceed 2^31 = 2147483648.
    |                            ^
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/remoc/src/chmux/cfg.rs:37
    |
 37 |  [Receiver::recv_chunk](super::Receiver::recv_chunk) is not affected by this limit.
    |             ^^^^^^^^^^
    | - chunkiness
    |
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/remoc/src/chmux/cfg.rs:62
    |
 62 |  This limit the number of chunks sendable by using
    |                                  ^^^^^^^^
    | - spendable, bendable, send able, send-able, or dependable
    |
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/remoc/src/chmux/cfg.rs:63
    |
 63 |  [Sender::try_send](super::Sender::try_send).
    |           ^^^^^^^^
    | - trendsetter
    |
    |   Possible spelling mistake found.



<SNIP>

error: spellcheck(Hunspell)
    --> /tmp/remoc/remoc_macro/src/trait_def.rs:456
     |
 456 | Remote server for [#ident] taking the target object by shared mutable reference.
     |                     ^^^^^
     | - dent, indent, i dent, or eventide
     |
     |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/remoc_macro/src/util.rs:25
    |
 25 |  TokenStream for list of attributes.
    |  ^^^^^^^^^^^
    | - Token Stream, Token-stream, or Downstream
    |
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/rpc_test/src/lib.rs:23
    |
 23 |  Const fn docs.
    |  ^^^^^
    | - Cons, Cont, Cost, Coast, Canst, Con st, Con-st, or one of 2 others
    |
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/rpc_test/src/lib.rs:23
    |
 23 |  Const fn docs.
    |        ^^
    | - fen, fin, fan, fun, en, in, fa, or one of 7 others
    |
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/rpc_test/src/lib.rs:28
    |
 28 |  Mut fn docs.
    |  ^^^
    | - Moet, Mt, Nut, Rut, Tut, Out, Cut, or one of 8 others
    |
    |   Possible spelling mistake found.

error: spellcheck(Hunspell)
   --> /tmp/remoc/rpc_test/src/lib.rs:28
    |
 28 |  Mut fn docs.
    |      ^^
    | - fen, fin, fan, fun, en, in, fa, or one of 7 others
    |
    |   Possible spelling mistake found.

You can get the latest source from https://github.com/ENQT-GmbH/remoc/

libhunspell is at 1.7-0 (Ubuntu).

I've tried again with cargo spellcheck 0.9.0-rc1 and there the bug seems to be fixed!

I tried again against e4f2866bd9ce1e9cbad6a8bacf5f860b0a5dc163 of the provided repo, I still cannot reproduce. Could you add a full end to end sequence of commands that reproduces the issue, 0.9.0-rc1 refactors quite a bit of how the checking is done, so the bug might be hit less frequently.

I assume this reproduces 100% for you?

Yes, I am checking against the same commit.

Just running cargo spellcheck, nothing else. I've created no configuration file or such.

I've checked against another repository and there it works fine.

surban@dino:~/dev/remoc$ git show -s
commit e4f2866bd9ce1e9cbad6a8bacf5f860b0a5dc163 (HEAD -> master, tag: v0.8.0, surban/master, origin/master, origin/HEAD)
Author: Sebastian Urban <surban@surban.net>
Date:   Thu Oct 21 15:27:15 2021 +0200

    Version 0.8.0
surban@dino:~/dev/remoc$ cargo spellcheck --version
cargo-spellcheck 0.8.14
surban@dino:~/dev/remoc$ cargo spellcheck
Segmentation fault
surban@dino:~/dev/remoc$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
surban@dino:~/dev/remoc$

Since the host lib is out of reach to fix, defaulting to a vendored version of hunspell by default seems to be the only tractable solution.
I played around with extracting the version information by expanding the API, but this is non trivial for the host provided shared lib. This is a bit orthogonal but will help triaging issues a lot.

Could you provide a container to reproduce this? Otherwise I am tempted to close this as won't fix since it's not in my power

Thanks. I will reopen when I hit the bug again, but probably the best solution in the long term is to switch to a Rust native spellchecking library.