`STATUS_STACK_BUFFER_OVERRUN` on Windows without any usage of unsafe

I have this small sample crash with STATUS_STACK_BUFFER_OVERRUN on Windows.

use std::cell::Cell;

struct Panicker;
impl Drop for Panicker {
    fn drop(&mut self) {
        panic!("Unhappy")
    }
}

fn main() {
    thread_local! {
        static P: Cell<Option<Panicker>> = const { Cell::new(None) };
    }
    
    P.set(Some(Panicker));

    println!("Done. Or am I?");
}

The question is whether I should worry about this issue (as in, is this a memory corruption issue).
Or am I fine leaving this code as is.

❯ cargo run
   Compiling panicker v0.1.0 (C:\Users\:3\Projects\panicker)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.41s
     Running `target\debug\panicker.exe`
Done. Or am I?

thread 'main' panicked at src\main.rs:6:9:
Unhappy
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: thread local panicked on drop
error: process didn't exit successfully: `target\debug\panicker.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
1 Like

Compiling your program with rustc 1.87.0-nightly (43f0014ef 2025-03-25) and running it on Linux also causes a memory corruption error:

Done. Or am I?

thread 'main' panicked at test.rs:6:9:
Unhappy
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: thread local panicked on drop
Segmentation fault (core dumped)

This post suggests that your error indeed indicates memory corruption. Memory corruption shouldn't happen in safe Rust.

Which compiler version are you using?

I tried:

rustc 1.81.0 (eeb90cda1 2024-09-04)
rustc 1.86.0 (05f9846f8 2025-03-31)
rustc 1.88.0-nightly (2fa8b11f0 2025-04-06)

The result was the same on all of them.

Interesting enough, on a linked playground it's SIGABRT, not SIGSEGV.

2 Likes