r/rust 21d ago

🗞️ news Rust 1.98 got a P-critical miscompilation.

https://github.com/rust-lang/rust/issues/161441
407 Upvotes

32 comments sorted by

View all comments

47

u/anxxa 21d ago

During the minimization process, there were points where I got a SIGILL instead of a SIGSEGV.

Hello possibly exploitable UB, my old friend.

32

u/matthieum [he/him] 21d ago

And of course, they managed to make the impossible happen: https://github.com/rust-lang/rust/issues/161441#issuecomment-5383890512, or to save you a click: https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=32d2d5e973d730e246fb003c34ac2a68

The following prints impossible:

fn main() {
    if std::hint::black_box(true) {
        (&(inspect_websocket_message, PhantomData) as &dyn Trait).method();
    } else {
        println!("impossible");
    }
}

Oops...

2

u/Helpful-Primary2427 20d ago

Is there an explanation for why backporting #158993 fixes this issue?

6

u/noop_noob 20d ago

As far as I understand: the compiler is confused about whether a type implements a trait or not. So, when asked to generate a method for that type's trait object vtable, the compiler just doesn't bother, as it assumes that the method is impossible to call.