rust-x-bindings / rust-xcb

Rust bindings and wrapper for XCB.
MIT License
165 stars 64 forks source link

Segfault from connect_with_extensions #130

Closed DanielChabrowski closed 2 years ago

DanielChabrowski commented 2 years ago

Hello, Found this issue by accident when my Xephyr instance closed. It seems that if you request any extension in connect_with_extensions and xcb cannot connect to specified display (Xephyr runs on :3 in my case) then we get a segfault when it tries to read extension data cache.

Repro:

fn main() {
    xcb::Connection::connect_with_extensions(None, &[xcb::Extension::XvMc], &[]).unwrap();
}
[package]
name = "xcb-repro"
version = "0.1.0"
edition = "2021"

[dependencies]
xcb = { version = "1.0.0-beta.1", features = ["xvmc"] }

bt:

DISPLAY=:2 gdb target/debug/xcb-repro
...
Program received signal SIGSEGV, Segmentation fault.
xcb::xproto::QueryExtensionReply::present (self=0x7fffffffd800) at /home/dante/projects/xcb-repro/target/debug/build/xcb-781268a8584f49d5/out/xproto.rs:21946
21946           let val = unsafe { *(self.wire_ptr().add(8usize)) };
(gdb) bt
#0  xcb::xproto::QueryExtensionReply::present (self=0x7fffffffd800) at /home/dante/projects/xcb-repro/target/debug/build/xcb-781268a8584f49d5/out/xproto.rs:21946
#1  0x0000555555560d76 in xcb::ext::cache_extensions_data (conn=0x7ffff7f9b05c, mandatory=..., optional=...) at /home/dante/.cargo/registry/src/github.com-1ecc6299db9ec823/xcb-1.0.0-beta.1/src/ext.rs:295
#2  0x0000555555563ecb in xcb::base::Connection::from_raw_conn_and_extensions (conn=0x7ffff7f9b05c, mandatory=..., optional=...) at /home/dante/.cargo/registry/src/github.com-1ecc6299db9ec823/xcb-1.0.0-beta.1/src/base.rs:875
#3  0x0000555555563bf0 in xcb::base::Connection::connect_with_extensions (display_name=..., mandatory=..., optional=...) at /home/dante/.cargo/registry/src/github.com-1ecc6299db9ec823/xcb-1.0.0-beta.1/src/base.rs:675
#4  0x000055555555d6e0 in xcb_repro::main () at src/main.rs:2

If it connects then it behaves as expected:

DISPLAY=:3 target/debug/xcb-repro                                                                                                                                                                                                                                                                                              
thread 'main' panicked at 'mandatory extension XVideo-MotionCompensation is not present on this system', /home/dante/.cargo/registry/src/github.com-1ecc6299db9ec823/xcb-1.0.0-beta.1/src/ext.rs:294:13                                                                                                                        
rtbo commented 2 years ago

Thank you for the detailed report. Closed by #132