-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#90 Seems to have come back again #99
Comments
I get same issue on nightly:
|
Minimal example: extern crate x11_dl;
use x11_dl::xlib_xcb;
fn main () {
unsafe {
let xlib_xcb = xlib_xcb::Xlib_xcb::open().unwrap();
}
} |
It was broken between rust-lang/rust@24a9bcb (nightly-2019-07-05) and rust-lang/rust@481068a (nightly-2019-07-06) |
Seemed to be caused by rust-lang/rust#62150, and doesn't affect other than xlib_xcb libraries. |
I suppose minimum supported rust version is from Debian Jessie. What if left 1.8.x with Debian Jessie minimum, and set new minimum supported rust version with |
Do you know which code on your end is creating the zeroed reference? A quick search brought up which looks... very bad.^^ There's not even a comment explaining what this is doing, or under which conditions it is safe to call---something that should be done for every How is it different from |
Ah yes, that's incorrect. |
I'm new to MaybeUninit, just heard about it when it was stabilized. Can you initialize parts of the struct at a time or does it have to all be in one go with My other thought to work through this would be to generate a struct with all fields as Options, write to the fields as you go, then convert to a struct with the same fields which aren't contained in Options. |
Unfortunately that's not possible yet in Rust. :/ This requires a solution for rust-lang/rfcs#2582. |
Ahhh okay, that's enough to get me started. I'll take a crack at it tomorrow when I have access to a Linux machine, thanks! |
It's been a long time since I wrote that code, so I don't remember what my reasoning was at the time, but it may be that I only know of As for this bug coming up again, using |
Interesting further discussion here: rust-lang/rust#52898 (comment) |
It would be great if someone who's uo-to-date on the project could look into this.
I think that is a very unfair characterization of what is going on. But this is being discussed in the other thread mentioned by @bschwind. |
Oh and for completeness' sake, the likely cause of this SIGILL is rust-lang/rust#62150. |
Btw, my best guess for where the bad function pointers are declared is If you want to zero/"uninit"-initialize that struct, these should definitely be |
@daggerbot How are the compile times if you have two versions of the struct, one with Option<fn...>/usize and one with the actual fn pointers. You use the first version to set all fields to 0 and initialize the values in a loop like happens now. Then, before passing it back to the user and after having asserted all fields != 0, you transmute the whole struct to the second version. I realize there is a good chance this isn't helping because you now have two versions of this giant struct. Perhaps you can work on an array of usizes directly instead and transmute that. |
The revert PR has just been merged in Rust upstream so fixing this issue isn't as urgent any more: rust-lang/rust#63343 . They will do the change sooner or later though so it should not be ignored. |
No, it's just as urgent. We only reverted this in Rust so that users of this crate don't have to suffer, and we want to un-do the revert as soon as we can. Basically, we granted you a reprieve. We would much appreciate if y'all could help us in this (help us keeping the compiler clean and not accumulate cruft) by fixing this bug in this crate. :) We will also land a lint on nightly soon (hopefully in time for the beta) that will help find code that uses |
@RalfJung it's not urgent for me because my project uses Rust nightly as well as x11-rs. As for helping this crate, I can't because the problem mostly seems to be blocked on maintainers. There is an open PR to fix it but they aren't merging it. And yeah I saw the lint PR as well, it's good to have it (would be good to warn on bad assume_init use too, right now the example right at the top of MaybeUninit docs is linting only for mem::uninitialized, not for MaybeUninit). |
We can't do the same warning on general |
Indeed the lint is firing:
|
With an ongoing PR, this now even points at the field causing the issue:
|
Improve invalid_value lint message The lint now explains which type is involved and why it cannot be initialized this way. It also points at the innermost struct/enum field that has an offending type, if any. See AltF02/x11-rs#99 (comment) for how this helps in some real-world code hitting this lint.
implement zeroed and uninitialized with MaybeUninit This is the second attempt of doing such a change (first PR: rust-lang#62150). The last change [got reverted](rust-lang#63343) because it [caused](rust-lang#62825) some [issues](rust-lang#52898 (comment)) in [code that incorrectly used these functions](AltF02/x11-rs#99). Since then, the [problematic code has been fixed](AltF02/x11-rs#101), and rustc [gained a lint](rust-lang#63346) that is able to detect many misuses of these functions statically and a [dynamic check that panics](rust-lang#66059) instead of causing UB for some incorrect uses. Fixes rust-lang#62825
implement zeroed and uninitialized with MaybeUninit This is the second attempt of doing such a change (first PR: rust-lang#62150). The last change [got reverted](rust-lang#63343) because it [caused](rust-lang#62825) some [issues](rust-lang#52898 (comment)) in [code that incorrectly used these functions](AltF02/x11-rs#99). Since then, the [problematic code has been fixed](AltF02/x11-rs#101), and rustc [gained a lint](rust-lang#63346) that is able to detect many misuses of these functions statically and a [dynamic check that panics](rust-lang#66059) instead of causing UB for some incorrect uses. Fixes rust-lang#62825
implement zeroed and uninitialized with MaybeUninit This is the second attempt of doing such a change (first PR: rust-lang#62150). The last change [got reverted](rust-lang#63343) because it [caused](rust-lang#62825) some [issues](rust-lang#52898 (comment)) in [code that incorrectly used these functions](AltF02/x11-rs#99). Since then, the [problematic code has been fixed](AltF02/x11-rs#101), and rustc [gained a lint](rust-lang#63346) that is able to detect many misuses of these functions statically and a [dynamic check that panics](rust-lang#66059) instead of causing UB for some incorrect uses. Fixes rust-lang#62825
Update x11-dl to pickup the fix for x11 startup crash (recurrence of #21530) This branch updates x11-dl to 2.18.5 to get AltF02/x11-rs#99 ``` % ./mach run --release https://duckduckgo.com attempted to leave type `std::mem::ManuallyDrop<xlib_xcb::Xlib_xcb>` uninitialized, which is invalid (thread main, at /rustc/45ebd5808afd3df7ba842797c0fcd4447ddf30fb/src/libcore/mem/mod.rs:536) stack backtrace: 0: servo::backtrace::print 1: servo::main::{{closure}} 2: std::panicking::rust_panic_with_hook at src/libstd/panicking.rs:513 3: rust_begin_unwind at src/libstd/panicking.rs:417 4: core::panicking::panic_fmt at src/libcore/panicking.rs:111 5: core::panicking::panic at src/libcore/panicking.rs:54 6: x11_dl::xlib_xcb::Xlib_xcb::open 7: winit::platform::platform::x11::xdisplay::XConnection::new 8: std::sync::once::Once::call_once::{{closure}} 9: std::sync::once::Once::call_inner at src/libstd/sync/once.rs:416 10: winit::platform::platform::EventsLoop::new_x11 11: winit::platform::platform::EventsLoop::new 12: winit::EventsLoop::new 13: servo::events_loop::EventsLoop::new 14: servo::app::App::run 15: servo::main 16: std::rt::lang_start::{{closure}} 17: std::rt::lang_start_internal::{{closure}} at src/libstd/rt.rs:52 std::panicking::try::do_call at src/libstd/panicking.rs:329 std::panicking::try::do_try at src/libstd/panicking.rs:285 std::panicking::try at src/libstd/panicking.rs:274 std::panic::catch_unwind at src/libstd/panic.rs:394 std::rt::lang_start_internal at src/libstd/rt.rs:51 18: main 19: __libc_start_main 20: _start Servo exited with return value 101 ``` This patch is created by `cargo update -p x11-dl`. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because it fixes a startup crash <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This fixes an unsoundness bug in x11-dl that caused a segfault on startup when compiled with certain Rust nightlies. AltF02/x11-rs#99
Issue #90 seems to have come back again...
The issue is really, really weird though; when I build in debug mode, I don't have this bug, but when I rebuild (completely from scratch) in release mode, it comes back to bite me. Here's the output from the
lldb
. Compiler info, etc., are in the Meta section below.Meta
The text was updated successfully, but these errors were encountered: