tiny: Tiny panicks when connecting to irc.gitter.im

Maybe I didn’t configure it correctly, but if so I couldn’t find what parameter is wrong and causing this issue:

thread 'main' panicked at 'byte index 13 is out of bounds of ` 1.10.0`', /rust/47c3158c3d797f75f0f7b2b2a977179668919dab/src/libcore/str/mod.rs:2052:47
    - addr: irc.gitter.im
      port: 6697
      tls: true
      realname: Kabouik
      nicks: [Kabouik]

      # (optional) Server alias for display in tab line
      alias: Gitter

      # Channels to automatically join
      join:
          - '#jarun/nnn'

      # Server or nick password
      pass: 'mytoken'

I tried with or without nicknames listed in nicks, with or without the channel, but no difference.

I followed instructions at https://irc.gitter.im/.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I can reproduce this locally.

First of all here’s a problem with tiny that is not specific to this bug: in case of a panic in a task we should really abort. I don’t know how tiny can continue operating after a panic (after all, we don’t spawn any threads, and AFAIK you can only catch panics in thread boundaries), but it clearly can, as otherwise there would be at most one panic reported in stderr in a panic.

Currently I get three panics, I think only the first one is relevant (others are chain reaction) so only pasting that:

Backtrace
thread 'main' panicked at 'byte index 13 is out of bounds of ` 1.10.0`', /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/str/mod.rs:2052:47
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:477
  11: rust_begin_unwind
             at src/libstd/panicking.rs:385
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:86
  13: core::str::slice_error_fail
             at src/libcore/str/mod.rs:0
  14: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::RangeFrom<usize>>::index::{{closure}}
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/str/mod.rs:2052
  15: core::option::Option<T>::unwrap_or_else
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/option.rs:430
  16: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::RangeFrom<usize>>::index
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/str/mod.rs:2052
  17: core::str::traits::<impl core::ops::index::Index<I> for str>::index
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/str/mod.rs:1780
  18: <alloc::string::String as core::ops::index::Index<core::ops::range::RangeFrom<usize>>>::index
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc/string.rs:2076
  19: libtiny_client::state::parse_servername
             at libtiny_client/src/state.rs:503
  20: libtiny_client::state::StateInner::update
             at libtiny_client/src/state.rs:324
  21: libtiny_client::state::State::update
             at libtiny_client/src/state.rs:39
  22: libtiny_client::main_loop::{{closure}}
             at libtiny_client/src/lib.rs:448
  23: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/future/mod.rs:73
  24: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/task/core.rs:173
  25: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/loom/std/unsafe_cell.rs:14
  26: tokio::runtime::task::core::Core<T,S>::poll
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/task/core.rs:158
  27: tokio::runtime::task::harness::Harness<T,S>::poll::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/task/harness.rs:107
  28: core::ops::function::FnOnce::call_once
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232
  29: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:318
  30: std::panicking::try::do_call
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:297
  31: __rust_try
  32: std::panicking::try
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:274
  33: std::panic::catch_unwind
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394
  34: tokio::runtime::task::harness::Harness<T,S>::poll
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/task/harness.rs:89
  35: tokio::runtime::task::raw::poll
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/task/raw.rs:104
  36: tokio::runtime::task::raw::RawTask::poll
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/task/raw.rs:66
  37: tokio::runtime::task::Notified<S>::run
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/task/mod.rs:169
  38: tokio::task::local::LocalSet::tick::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/task/local.rs:406
  39: tokio::coop::with_budget::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/coop.rs:127
  40: std::thread::local::LocalKey<T>::try_with
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/local.rs:263
  41: std::thread::local::LocalKey<T>::with
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/local.rs:239
  42: tokio::coop::with_budget
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/coop.rs:120
  43: tokio::coop::budget
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/coop.rs:96
  44: tokio::task::local::LocalSet::tick
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/task/local.rs:406
  45: <tokio::task::local::RunUntil<T> as core::future::future::Future>::poll::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/task/local.rs:530
  46: tokio::macros::scoped_tls::ScopedKey<T>::set
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/macros/scoped_tls.rs:63
  47: tokio::task::local::LocalSet::with
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/task/local.rs:440
  48: <tokio::task::local::RunUntil<T> as core::future::future::Future>::poll
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/task/local.rs:516
  49: tokio::task::local::LocalSet::run_until::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/task/local.rs:390
  50: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/future/mod.rs:73
  51: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on::{{closure}}::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/basic_scheduler.rs:131
  52: tokio::coop::with_budget::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/coop.rs:127
  53: std::thread::local::LocalKey<T>::try_with
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/local.rs:263
  54: std::thread::local::LocalKey<T>::with
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/local.rs:239
  55: tokio::coop::with_budget
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/coop.rs:120
  56: tokio::coop::budget
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/coop.rs:96
  57: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/basic_scheduler.rs:131
  58: tokio::runtime::basic_scheduler::enter::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/basic_scheduler.rs:213
  59: tokio::macros::scoped_tls::ScopedKey<T>::set
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/macros/scoped_tls.rs:63
  60: tokio::runtime::basic_scheduler::enter
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/basic_scheduler.rs:213
  61: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/basic_scheduler.rs:123
  62: tokio::runtime::Runtime::block_on::{{closure}}
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/mod.rs:444
  63: tokio::runtime::context::enter
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/context.rs:72
  64: tokio::runtime::handle::Handle::enter
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/handle.rs:76
  65: tokio::runtime::Runtime::block_on
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/runtime/mod.rs:441
  66: tokio::task::local::LocalSet::block_on
             at /home/omer/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/task/local.rs:351
  67: tiny::run
             at tiny/src/main.rs:103
  68: tiny::main
             at tiny/src/main.rs:65
  69: std::rt::lang_start::{{closure}}
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  70: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  71: std::panicking::try::do_call
             at src/libstd/panicking.rs:297
  72: std::panicking::try
             at src/libstd/panicking.rs:274
  73: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  74: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  75: std::rt::lang_start
             at /home/omer/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  76: main
  77: __libc_start_main
  78: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

The bug is in this function:

/// Try to parse servername in a 002 RPL_YOURHOST reply
fn parse_servername(params: &[String]) -> Option<String> {
    let msg = params.get(1).or_else(|| params.get(0))?;
    let slice1 = &msg[13..];
    let servername_ends = slice1.find('[').or_else(|| slice1.find(','))?;
    Some((&slice1[..servername_ends]).to_owned())
}

Here the magic number 13 is the length of string "Your host is ". This assumes that RPL_YOURHOST messages always start with that prefix. This is per RFC 2812, which defines response format as

       002    RPL_YOURHOST
              "Your host is <servername>, running version <ver>"

Apparently this server doesn’t follow this format.

The function parse_servername is very fragile and we should make sure to check all bounds here. I’ll update the code.

Reminder: the server name parsed in this function is used when pinging the server when we don’t hear from it for a while. If we can’t parse server name of a server then send_ping simply returns.

The params look incorrectly parsed where the debug_assert is panicking. params["trevarj", "Gitter", "trevarj!trevarj@irc.gitter.im"]

Should be like this I think : params["trevarj", "Gitter trevarj!trevarj@irc.gitter.im"]

    001    RPL_WELCOME
              "Welcome to the Internet Relay Network
               <nick>!<user>@<host>"

Edit: @osa1 I think it’s because this is the full message that the server sends: :irc.gitter.im 001 trevarj Gitter :trevarj!trevarj@irc.gitter.im and then parse_params in libtiny_wire::lib.rsis splitting on that second colon.

To me it seems like this is the server’s fault? They should be sending the message like :irc.gitter.im 001 trevarj :Gitter trevarj!trevarj@irc.gitter.im. In the examples of RPL_WELCOME messages it appears that this is the acceptable format.

One more edit: https://gitlab.com/gitlab-org/gitter/irc-bridge/-/blob/develop/lib/gitter-adapter.js#L271