error STATUS_STACK_BUFFER_OVERRUN out of nowhere

Viewed 75

The recent days I've been encountering this

thread panicked while panicking. aborting.
error: test failed, to rerun pass '--lib'

Caused by:
  process didn't exit successfully: `C:\Users\Windows10\Projects\Rust\current\rs-sb3\target\debug\deps\sb3-44311f04214ba6d4.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

Some day when I open my laptop, the code will just unit test perfectly fine. But after some modification to the code then the error will appear. If I tried to comment out the suspect code then the error will still come up. After awhile I cloned the repo to my pc then it works. Some modification later, the error came up.

This is my repo. I cannot provide the exact code due to my zero understanding of the problem.

1 Answers

It's a bug in assert_eq_sorted.

I managed to reduce it down to the following minimal reproducible example:

#[cfg(test)]
mod test {
    use pretty_assertions_sorted::assert_eq_sorted;
    use serde_json::json;

    #[test]
    fn double_panic() {
        assert_eq_sorted!(json!({"a":0}), json!(null));
    }
}

When run with cargo test -- --nocapture:

running 1 test
thread 'test::double_panic' panicked at 'Failed to parse Debug output, err: Failed to consume all of string!
Value:
Object

Rest:
" {\"a\": Number(0)}"', /home/finomnis/.cargo/registry/src/github.com-1ecc6299db9ec823/pretty_assertions_sorted-1.2.0/src/lib.rs:101:17
stack backtrace:
   0:     0x56291e9c8e3d - std::backtrace_rs::backtrace::libunwind::trace::h8217d0a8f3fd2f41
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x56291e9c8e3d - std::backtrace_rs::backtrace::trace_unsynchronized::h308103876b3af410
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x56291e9c8e3d - std::sys_common::backtrace::_print_fmt::hc208018c6153605e
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x56291e9c8e3d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf89a7ed694dfb585
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x56291e9ebc1c - core::fmt::write::h21038c1382fe4264
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1197:17
   5:     0x56291e9c5931 - std::io::Write::write_fmt::h7dbb1c9a3c254aef
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/mod.rs:1672:15
   6:     0x56291e9ca8b5 - std::sys_common::backtrace::_print::h4e8889719c9ddeb8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x56291e9ca8b5 - std::sys_common::backtrace::print::h1506fe2cb3022667
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x56291e9ca8b5 - std::panicking::default_hook::{{closure}}::hd9d7ce2a8a782440
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:295:22
   9:     0x56291e9ca5d6 - std::panicking::default_hook::h5b16ec25444b1b5d
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:314:9
  10:     0x56291e9cae46 - std::panicking::rust_panic_with_hook::hb0138cb6e6fea3e4
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:698:17
  11:     0x56291e9cad37 - std::panicking::begin_panic_handler::{{closure}}::h4cb67095557cd1aa
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:588:13
  12:     0x56291e9c92f4 - std::sys_common::backtrace::__rust_end_short_backtrace::h2bfcac279dcdc911
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x56291e9caa69 - rust_begin_unwind
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
  14:     0x56291e8f33e3 - core::panicking::panic_fmt::h1de71520faaa17d3
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
  15:     0x56291e8f8f18 - <pretty_assertions_sorted::SortedDebug<T> as core::fmt::Debug>::fmt::h57312b215cce8a2d
                               at /home/finomnis/.cargo/registry/src/github.com-1ecc6299db9ec823/pretty_assertions_sorted-1.2.0/src/lib.rs:101:17
  16:     0x56291e8f8cb6 - <&T as core::fmt::Debug>::fmt::h08992fb97cb26304
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:2135:62
  17:     0x56291e9ebb9b - core::fmt::run::h04a2d130287fdf44
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1245:5
  18:     0x56291e9ebb9b - core::fmt::write::h21038c1382fe4264
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1213:26
  19:     0x56291e9e61b9 - core::fmt::Write::write_fmt::hb01fdc89301b9dd0
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:187:9
  20:     0x56291e9e61b9 - alloc::fmt::format::format_inner::h3fdf7b01996f555c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/fmt.rs:612:9
  21:     0x56291e957ce1 - alloc::fmt::format::{{closure}}::h8d5a6d5a9f27ae79
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/fmt.rs:616:34
  22:     0x56291e958fea - core::option::Option<T>::map_or_else::h2173b95551bac11e
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/option.rs:1023:21
  23:     0x56291e8f81ee - alloc::fmt::format::hec789ac598d607bd
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/fmt.rs:616:5
  24:     0x56291e8f90ec - <pretty_assertions::Comparison<TLeft,TRight> as core::fmt::Display>::fmt::hebb40026d1dd72ef
                               at /home/finomnis/.cargo/registry/src/github.com-1ecc6299db9ec823/pretty_assertions-1.3.0/src/lib.rs:135:26
  25:     0x56291e9ebc1c - core::fmt::write::h21038c1382fe4264
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1197:17
  26:     0x56291e9cabdc - core::fmt::Write::write_fmt::h7dde5490f740f43d
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:187:9
  27:     0x56291e9cabdc - std::panicking::begin_panic_handler::PanicPayload::fill::{{closure}}::he65d23c331dfcce3
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:550:22
  28:     0x56291e9cabdc - core::option::Option<T>::get_or_insert_with::hb4d636eeeddd23cb
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/option.rs:1544:49
  29:     0x56291e9cabdc - std::panicking::begin_panic_handler::PanicPayload::fill::h4e79032a5d9ce017
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:548:13
  30:     0x56291e9cabdc - <std::panicking::begin_panic_handler::PanicPayload as core::panic::BoxMeUp>::get::h7f9447447ad87273
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:566:13
  31:     0x56291e9cae31 - std::panicking::rust_panic_with_hook::hb0138cb6e6fea3e4
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:697:34
  32:     0x56291e9cad37 - std::panicking::begin_panic_handler::{{closure}}::h4cb67095557cd1aa
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:588:13
  33:     0x56291e9c92f4 - std::sys_common::backtrace::__rust_end_short_backtrace::h2bfcac279dcdc911
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:138:18
  34:     0x56291e9caa69 - rust_begin_unwind
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
  35:     0x56291e8f33e3 - core::panicking::panic_fmt::h1de71520faaa17d3
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
  36:     0x56291e8f3eea - rust_tmp::test::double_panic::h45d788b1dd43b0d6
                               at /home/finomnis/work/rust-tmp/src/lib.rs:8:9
  37:     0x56291e8f8c6a - rust_tmp::test::double_panic::{{closure}}::h2e78776b44f9e8d8
                               at /home/finomnis/work/rust-tmp/src/lib.rs:7:5
  38:     0x56291e8f858e - core::ops::function::FnOnce::call_once::haa7b0260a53ae747
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
  39:     0x56291e92e7b3 - core::ops::function::FnOnce::call_once::h0834638dccd7f44f
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
  40:     0x56291e92e7b3 - test::__rust_begin_short_backtrace::h236b9d3086614016
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/test/src/lib.rs:572:5
  41:     0x56291e92d5ba - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h836d617c8cafab84
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/boxed.rs:1951:9
  42:     0x56291e92d5ba - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h749e4286e2b07713
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panic/unwind_safe.rs:271:9
  43:     0x56291e92d5ba - std::panicking::try::do_call::h43a1b83a3cb9edc8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  44:     0x56291e92d5ba - std::panicking::try::h5622fa742e7f1abc
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  45:     0x56291e92d5ba - std::panic::catch_unwind::h99900a1dadf94a68
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  46:     0x56291e92d5ba - test::run_test_in_process::h3893e153ea830832
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/test/src/lib.rs:595:18
  47:     0x56291e92d5ba - test::run_test::run_test_inner::{{closure}}::h1a6c1ab1f6c36f74
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/test/src/lib.rs:489:39
  48:     0x56291e8f9b2d - test::run_test::run_test_inner::{{closure}}::hb34d5332aa2ee72c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/test/src/lib.rs:516:37
  49:     0x56291e8f9b2d - std::sys_common::backtrace::__rust_begin_short_backtrace::h99ab4c6a3071a36c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:122:18
  50:     0x56291e8ff558 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h27cba0714207d393
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/thread/mod.rs:505:17
  51:     0x56291e8ff558 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h9cf84e534f80e48a
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panic/unwind_safe.rs:271:9
  52:     0x56291e8ff558 - std::panicking::try::do_call::hcd5ff80e96737b38
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  53:     0x56291e8ff558 - std::panicking::try::h1813b6532a9dacd8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  54:     0x56291e8ff558 - std::panic::catch_unwind::hff2a46cca1d01f0b
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  55:     0x56291e8ff558 - std::thread::Builder::spawn_unchecked_::{{closure}}::h83c4b74ca1b724fc
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/thread/mod.rs:504:30
  56:     0x56291e8ff558 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h9e3eb359359c7897
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
  57:     0x56291e9cf5f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1680342795a2dc08
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/boxed.rs:1951:9
  58:     0x56291e9cf5f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h45204a69827b0e83
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/boxed.rs:1951:9
  59:     0x56291e9cf5f3 - std::sys::unix::thread::Thread::new::thread_start::h5d4e11bbda4161c8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys/unix/thread.rs:108:17
  60:     0x7f595c40b609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  61:     0x7f595c1db133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  62:                0x0 - <unknown>
thread panicked while panicking. aborting.

It seems that the pretty_assertions_sorted crate has a panic! in one of its functions, causing a double panic.

Disclaimer - personal opinion: Such an error is an indication of bad programming style, in my opinion. I'd avoid the crate for now. (time of writing: pretty_assertions_sorted 1.2.0)


Here is the full reproduction of the error:

#[cfg(test)]
mod test {
    use pretty_assertions_sorted::{assert_eq_sorted, Comparison, SortedDebug};
    use serde_json::json;

    #[test]
    fn double_panic_highlevel() {
        assert_eq_sorted!(json!({"a":0}), json!(null));
    }

    #[test]
    fn double_panic_midlevel1() {
        format!(
            "{}",
            Comparison::new(
                &SortedDebug::new(json!({"a":0})),
                &SortedDebug::new(json!(null))
            )
        );
    }

    #[test]
    fn double_panic_midlevel2() {
        format!("{:#?}", &SortedDebug::new(json!({"a":0})));
    }

    #[test]
    fn double_panic_lowlevel1() {
        darrentsung_debug_parser::parse(&format!("{:?}", json!({"a":0}))).unwrap();
    }

    #[test]
    fn double_panic_lowlevel2() {
        darrentsung_debug_parser::parse("Object {\"a\": Number(0)}").unwrap();
    }
}
Related