Skip to content

Rust 1.65 - failed assert_eq! causes crash with SIGSEGV #104441

Closed
@wg

Description

@wg

I tried this code:

assert_eq!("foo", "bar");

I expected the program to panic with an assertion failed message and exit normally:

% cargo +1.64.0 run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/test-segv`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"foo"`,
 right: `"bar"`', src/main.rs:7:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Instead, the program crashes with a segfault:

% cargo +1.65.0 run
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/test-segv`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"foo"`,
 right: `"bar"`', src/main.rs:7:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
zsh: segmentation fault  cargo +1.65.0 run

This is particularly a problem with tests since the test harness doesn't print the failed assert:

running 1 test
error: test failed, to rerun pass `--bin test-segv`

Caused by:
  process didn't exit successfully: `.../target/debug/deps/test_segv-1bd8c9f311fdbb76` (signal: 11, SIGSEGV: invalid memory reference)

This crash occurs on aarch64-apple-darwin, it does not occur on aarch64-unknown-linux-gnu

Meta

% cargo +1.65.0 rustc -- --version --verbose
   Compiling test-segv v0.0.1 (/Users/will/src/rust-play/test-segv)
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: aarch64-apple-darwin
release: 1.65.0
LLVM version: 15.0.0
Backtrace Backtrace from lldb:

* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001ca48f4f4 libunwind.dylib`libunwind::CFI_Parser<libunwind::LocalAddressSpace>::decodeFDE(libunwind::LocalAddressSpace&, unsigned long, libunwind::CFI_Parser<libunwind::LocalAddressSpace>::FDE_Info*, libunwind::CFI_Parser<libunwind::LocalAddressSpace>::CIE_Info*) + 48
    frame #1: 0x00000001ca49159c libunwind.dylib`libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm64>::step() + 204
    frame #2: 0x00000001ca493314 libunwind.dylib`_Unwind_RaiseException + 468
    frame #3: 0x000000010001a3e0 test-segv`rust_panic at panicking.rs:746:9 [opt]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions