Skip to content
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

Panic when listening for IBus messages #965

Open
brandonskiser opened this issue Aug 29, 2024 · 1 comment
Open

Panic when listening for IBus messages #965

brandonskiser opened this issue Aug 29, 2024 · 1 comment

Comments

@brandonskiser
Copy link

When trying to listen for IBus messages on the "org.freedesktop.IBus.InputContext" interface, zbus panics because a message is being passed with a sender that isn't a unique name. A sender with something like "org.freedesktop.IBus.InputContext" is being passed instead, which causes a panic.

Here is some code for reference that causes the panic - running this and then focusing out of the terminal causes the panic.

use tokio::process::Command;
use zbus::export::futures_util::TryStreamExt;
use zbus::fdo::DBusProxy;
use zbus::{ConnectionBuilder, MatchRule, MessageStream};

#[tokio::main]
async fn main() {
    // Taking the ibus address from running `ibus address`
    let ibus_address = {
        let output = Command::new("ibus").arg("address").output().await.unwrap();
        String::from_utf8(output.stdout).unwrap().trim().to_owned()
    };
    println!("IBus address: {ibus_address}");

    let ibus_connection = ConnectionBuilder::address(ibus_address.as_str())
        .unwrap()
        .build()
        .await
        .unwrap();
    // Listening on DBus
    DBusProxy::new(&ibus_connection)
        .await
        .unwrap()
        .add_match_rule(
            MatchRule::builder()
                .interface("org.freedesktop.IBus.InputContext")
                .unwrap()
                .build(),
        )
        .await
        .unwrap();
    let mut stream = MessageStream::from(ibus_connection);
    loop {
        // Panics here when focusing out of a terminal.
        match stream.try_next().await {
            Ok(msg) => {
                println!("Message: {:?}", msg);
            }
            Err(err) => eprintln!("Error: {:?}", err),
        }
    }
}

Here is a resulting stack trace

thread 'zbus::Connection executor' panicked at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/message/fields.rs:137:22:
Invalid field reconstruction: InvalidUniqueName("must start with a `:`")
stack backtrace:
   0:     0x5d28d4f2a985 - std::backtrace_rs::backtrace::libunwind::trace::h58eed11393533053
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x5d28d4f2a985 - std::backtrace_rs::backtrace::trace_unsynchronized::h6af9bae28ebb6388
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5d28d4f2a985 - std::sys_common::backtrace::_print_fmt::hb6748916642a4fb2
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x5d28d4f2a985 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3692694645b1bb6a
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x5d28d4f53a4b - core::fmt::rt::Argument::fmt::h7aa93977ba74ae0f
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/fmt/rt.rs:165:63
   5:     0x5d28d4f53a4b - core::fmt::write::h5131d80b4c69b88d
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/fmt/mod.rs:1168:21
   6:     0x5d28d4f2739f - std::io::Write::write_fmt::h1fb327a7d8b0eb36
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/io/mod.rs:1835:15
   7:     0x5d28d4f2a75e - std::sys_common::backtrace::_print::he6ebb7b9d89f4456
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x5d28d4f2a75e - std::sys_common::backtrace::print::h998d75b840f75a73
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x5d28d4f2bca9 - std::panicking::default_hook::{{closure}}::h18ec7fe6a38b9da0
  10:     0x5d28d4f2ba4a - std::panicking::default_hook::hfb3f22c2e4075a6a
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:298:9
  11:     0x5d28d4f2c143 - std::panicking::rust_panic_with_hook::h51af00bcb4660c4e
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:795:13
  12:     0x5d28d4f2c024 - std::panicking::begin_panic_handler::{{closure}}::h39f76aa863fbe8ce
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:664:13
  13:     0x5d28d4f2ae49 - std::sys_common::backtrace::__rust_end_short_backtrace::h4d10fc2251b89840
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/sys_common/backtrace.rs:171:18
  14:     0x5d28d4f2bd57 - rust_begin_unwind
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:652:5
  15:     0x5d28d4a92a53 - core::panicking::panic_fmt::h319840fcbcd912ef
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/panicking.rs:72:14
  16:     0x5d28d4a93026 - core::result::unwrap_failed::haccb9aaa604e1e21
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/result.rs:1679:5
  17:     0x5d28d4caa52f - core::result::Result<T,E>::expect::h559f5d16af001476
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/result.rs:1059:23
  18:     0x5d28d4c35d1b - zbus::message::fields::FieldPos::read::h300fae1985eb196a
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/message/fields.rs:135:17
  19:     0x5d28d4c369a7 - zbus::message::fields::QuickFields::sender::h3e2a24539a96a1d8
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/message/fields.rs:197:9
  20:     0x5d28d4cd16dc - zbus::message::Message::header::hfbc4ede54dbbf526
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/message/mod.rs:189:26
  21:     0x5d28d4b14e63 - zbus::match_rule::MatchRule::matches::h29f054a476a40502
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/match_rule/mod.rs:212:19
  22:     0x5d28d4c6f11c - zbus::connection::socket_reader::SocketReader::receive_msg::{{closure}}::{{closure}}::h3ebdc79bda9221fe
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/connection/socket_reader.rs:61:31
  23:     0x5d28d4c6c1e1 - zbus::connection::socket_reader::SocketReader::receive_msg::{{closure}}::hb23933999825144d
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/connection/socket_reader.rs:47:5
  24:     0x5d28d4c461b3 - async_executor::Executor::spawn_inner::{{closure}}::hf66c5a1a21c9c7fe
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.13.0/src/lib.rs:250:20
  25:     0x5d28d4ae88f1 - async_task::raw::RawTask<F,T,S,M>::run::{{closure}}::h7da6b17c2f332cb2
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/raw.rs:550:21
  26:     0x5d28d4aaa43c - core::ops::function::FnOnce::call_once::h0514624f849be21d
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/ops/function.rs:250:5
  27:     0x5d28d4b68954 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h7e6cd1773cee9336
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/panic/unwind_safe.rs:272:9
  28:     0x5d28d4b38a17 - std::panicking::try::do_call::h938f339a9ab30241
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:559:40
  29:     0x5d28d4b6722b - __rust_try
  30:     0x5d28d4b38244 - std::panicking::try::hfb9467bbf070c7e7
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:523:19
  31:     0x5d28d4c796db - std::panic::catch_unwind::h927985a189660961
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panic.rs:149:14
  32:     0x5d28d4ad48c9 - async_task::raw::RawTask<F,T,S,M>::run::h4b4c9882dbe5289c
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/raw.rs:549:23
  33:     0x5d28d4d61c4f - async_task::runnable::Runnable<M>::run::hd10d856a1b8e00de
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/runnable.rs:781:18
  34:     0x5d28d4c41f27 - async_executor::State::tick::{{closure}}::h24d40022cc2af1d3
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.13.0/src/lib.rs:729:9
  35:     0x5d28d4c4729b - async_executor::Executor::tick::{{closure}}::h57f02597778f4d93
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.13.0/src/lib.rs:325:29
  36:     0x5d28d4ba98df - zbus::abstractions::executor::Executor::tick::{{closure}}::h6f82ab79b705702e
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/abstractions/executor.rs:86:34
  37:     0x5d28d4b58e81 - zbus::connection::builder::start_internal_executor::{{closure}}::{{closure}}::h4eb6e6b194f67743
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/connection/builder.rs:574:41
  38:     0x5d28d4d3755a - async_io::driver::block_on::{{closure}}::hec1e2f343f2dbd00
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-io-2.3.4/src/driver.rs:199:37
  39:     0x5d28d4ba608a - std::thread::local::LocalKey<T>::try_with::h4ea30751229ac47c
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/thread/local.rs:283:12
  40:     0x5d28d4ba5d8b - std::thread::local::LocalKey<T>::with::h17f0a6be6f96e4b9
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/thread/local.rs:260:9
  41:     0x5d28d4d3718e - async_io::driver::block_on::h9420511cc6ef1195
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-io-2.3.4/src/driver.rs:175:5
  42:     0x5d28d4c69067 - zbus::utils::block_on::ha305cc83e65ae1dd
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/utils.rs:34:5
  43:     0x5d28d4b58d74 - zbus::connection::builder::start_internal_executor::{{closure}}::hba20b6c16f2b92b7
                               at /home/ANT.AMAZON.COM/bskiser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zbus-4.4.0/src/connection/builder.rs:571:17
  44:     0x5d28d4ba465e - std::sys_common::backtrace::__rust_begin_short_backtrace::h1443d3d0153dcc04
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/sys_common/backtrace.rs:155:18
  45:     0x5d28d4cc2e5b - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::hc6c7dcc1138f73d0
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/thread/mod.rs:542:17
  46:     0x5d28d4b6892f - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h695ab128d71fe642
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/panic/unwind_safe.rs:272:9
  47:     0x5d28d4b38d36 - std::panicking::try::do_call::hf6188f6947b4a0ca
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:559:40
  48:     0x5d28d4b6722b - __rust_try
  49:     0x5d28d4b37cd0 - std::panicking::try::hb7b57e26f43c0069
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:523:19
  50:     0x5d28d4cc2cad - std::panic::catch_unwind::h25991521778c9638
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panic.rs:149:14
  51:     0x5d28d4cc2cad - std::thread::Builder::spawn_unchecked_::{{closure}}::hcea052d76a959afd
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/thread/mod.rs:541:30
  52:     0x5d28d4aa9f2f - core::ops::function::FnOnce::call_once{{vtable.shim}}::h6975001f3ee6df3d
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/ops/function.rs:250:5
  53:     0x5d28d4f3043b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3af90da315d4b185
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/alloc/src/boxed.rs:2063:9
  54:     0x5d28d4f3043b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4e7f3b3405b4b88b
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/alloc/src/boxed.rs:2063:9
  55:     0x5d28d4f3043b - std::sys::pal::unix::thread::Thread::new::thread_start::h3b8e81128811868f
                               at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/sys/pal/unix/thread.rs:108:17
  56:     0x72b3d0c94ac3 - <unknown>
  57:     0x72b3d0d26850 - <unknown>
  58:                0x0 - <unknown>
@zeenix
Copy link
Contributor

zeenix commented Aug 30, 2024

Thank you for reporting this. We definitely shoudn't panic here so this bug is very valid. However, the solution would involve erroring out or ignoring the non-compliant message (sender header field is supposed to be a unique name and it must start with a : according to the spec).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants