quininer/x11-clipboard

load_wait crash when copying from chrome address bar

wrvsrx opened this issue · 1 comments

Reproduce

  1. compile and run following script with RUST_BACKTRACE=1:
use x11_clipboard::Clipboard;
fn main() {
    let clipboard = Clipboard::new().unwrap();

    loop {
        let val = clipboard
            .load_wait(
                clipboard.setter.atoms.clipboard,
                clipboard.setter.atoms.utf8_string,
                clipboard.setter.atoms.property
            )
            .unwrap();
        println!("{}", val.len());

        let val = String::from_utf8(val).unwrap();

        println!("{}", val);
    }
}
  1. copy from chrome address bar
  2. It crashes with following information:
23
https://www.google.com/
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnexpectedType(0)', src/main.rs:12:14
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: core::result::Result<T,E>::unwrap
             at /build/rustc-1.65.0-src/library/core/src/result.rs:1107:23
   4: x11_test::main
             at ./src/main.rs:6:19
   5: core::ops::function::FnOnce::call_once
             at /build/rustc-1.65.0-src/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Reason

Google chrome has a strange behavior: it send xcb_xfixes_selection_notify_event_t twice when coping from address bar. Therefore loop in process_event meet XfixesSelectionNotify (

Event::XfixesSelectionNotify(event) if use_xfixes => {
) twice at first and call convert_selection twice (
self.getter.connection.convert_selection(
) before recive SelectioniNotify (you can verify it by log), which makes reply.type_ become zero and UnexpectedType error raise.

Fix

After get XfixesSelectionNotify, only wait for SelectionNotify and PropertyNotify.

Maybe I can make a PR later.

This is not a crash, load_wait returns an error as expected.

The crate is in a maintenance state and I am not willing to make behavior change.