tower-web icon indicating copy to clipboard operation
tower-web copied to clipboard

assertion failed: self.remaining_mut() >= src.remaining()

Open shepmaster opened this issue 7 years ago • 5 comments

thread 'tokio-runtime-worker-0' panicked at 'assertion failed: self.remaining_mut() >= src.remaining()', /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/bytes-0.4.8/src/buf/buf_mut.rs:229:9
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
             at libstd/panicking.rs:475
   5: std::ffi::c_str::CStr::to_bytes
             at /Users/travis/build/rust-lang/rust/src/libstd/panicking.rs:409
   6: bytes::buf::buf_mut::BufMut::put
             at ./<panic macros>:3
   7: <tower_web::extract::serde::SerdeFuture<T, B> as tower_web::extract::ExtractFuture>::poll
             at /Users/shep/Projects/tower-web/src/extract/serde.rs:145
   8: <ui::__IMPL_EXTRACT_FOR_CompileRequest::ExtractFuture<B> as tower_web::extract::ExtractFuture>::poll
             at src/main.rs:552
   9: <tower_web::util::tuple::Join1<T0> as futures::future::Future>::poll
             at /Users/shep/Projects/tower-web/src/util/tuple.rs:642
  10: <tower_web::util::tuple::Either1<A> as futures::future::Future>::poll
             at /Users/shep/Projects/tower-web/src/util/tuple.rs:81
  11: <ui::tower_web_server::__IMPL_WEB_1_FOR_Sandbox::ResponseFuture<S, B> as futures::future::Future>::poll
             at ./<derive_resource macros>:2
  12: <T as tower_web::service::future::HttpResponseFuture>::poll_http_response
             at /Users/shep/Projects/tower-web/src/service/future.rs:44
  13: <tower_web::util::tuple::Either2<A, B> as tower_web::service::future::HttpResponseFuture>::poll_http_response
             at /Users/shep/Projects/tower-web/src/util/tuple.rs:275
  14: <tower_web::util::tuple::LiftHttpResponse<T> as futures::future::Future>::poll
             at /Users/shep/Projects/tower-web/src/util/tuple.rs:27
  15: <futures::future::map::Map<A, F> as futures::future::Future>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/map.rs:30
  16: <alloc::boxed::Box<F> as futures::future::Future>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/mod.rs:113
  17: <hyper::proto::h1::dispatch::Server<S> as hyper::proto::h1::dispatch::Dispatch>::poll_msg
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.7/src/proto/h1/dispatch.rs:379
  18: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T>>::poll_write
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.7/src/proto/h1/dispatch.rs:237
  19: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T>>::poll_inner
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.7/src/proto/h1/dispatch.rs:101
  20: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T>>::poll_catch
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.7/src/proto/h1/dispatch.rs:86
  21: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T> as futures::future::Future>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.7/src/proto/h1/dispatch.rs:348
  22: <futures::future::either::Either<A, B> as futures::future::Future>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/either.rs:35
  23: futures::future::option::<impl futures::future::Future for core::option::Option<F>>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/option.rs:12
  24: <hyper::server::conn::Connection<I, S> as futures::future::Future>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.7/src/server/conn.rs:502
  25: <futures::future::map::Map<A, F> as futures::future::Future>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/map.rs:30
  26: <futures::future::map_err::MapErr<A, F> as futures::future::Future>::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/map_err.rs:30
  27: core::num::<impl usize>::max_value
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/mod.rs:113
  28: <bool as core::fmt::Debug>::fmt
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:289
  29: <bool as core::fmt::Debug>::fmt
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:363
  30: futures::task_impl::std::CURRENT_THREAD_NOTIFY::__init
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/std/mod.rs:78
  31: <bool as core::fmt::Debug>::fmt
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:363
  32: <bool as core::fmt::Debug>::fmt
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:289
  33: tokio_threadpool::task::TaskFuture::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/task/mod.rs:292
  34: tokio_threadpool::task::Task::run::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/task/mod.rs:165
  35: core::ops::function::FnOnce::call_once
             at /Users/travis/build/rust-lang/rust/src/libcore/ops/function.rs:223
  36: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panic.rs:313
  37: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panicking.rs:310
  38: panic_unwind::dwarf::eh::read_encoded_pointer
             at libpanic_unwind/lib.rs:106
  39: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panicking.rs:289
  40: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panic.rs:392
  41: tokio_threadpool::task::Task::run
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/task/mod.rs:151
  42: tokio_threadpool::worker::Worker::run_task2
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:545
  43: tokio_threadpool::worker::Worker::run_task
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:445
  44: tokio_threadpool::worker::Worker::try_run_owned_task
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:385
  45: tokio_threadpool::worker::Worker::try_run_task
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:293
  46: tokio_threadpool::worker::Worker::with_current::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:239
  47: tokio::runtime::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.7/src/runtime/builder.rs:125
  48: <std::collections::hash::table::SafeHash as core::cmp::PartialEq>::eq
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.4/src/timer/handle.rs:64
  49: std::sync::mpsc::blocking::SignalToken::cast_from_usize
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  50: std::sync::mpsc::blocking::SignalToken::cast_from_usize
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  51: <std::collections::hash::table::SafeHash as core::cmp::PartialEq>::eq
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.4/src/timer/handle.rs:56
  52: tokio::runtime::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.7/src/runtime/builder.rs:124
  53: futures::task_impl::core::get_ptr
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.4/src/clock/clock.rs:136
  54: std::sync::mpsc::blocking::SignalToken::cast_from_usize
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  55: std::sync::mpsc::blocking::SignalToken::cast_from_usize
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  56: futures::task_impl::core::get_ptr
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.4/src/clock/clock.rs:119
  57: tokio::runtime::builder::Builder::build::{{closure}}::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.7/src/runtime/builder.rs:123
  58: tokio::runtime::Runtime::inner
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.2/src/lib.rs:231
  59: std::sync::mpsc::blocking::SignalToken::cast_from_usize
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  60: std::sync::mpsc::blocking::SignalToken::cast_from_usize
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  61: tokio::runtime::Runtime::inner
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.2/src/lib.rs:214
  62: tokio::runtime::builder::Builder::build::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.7/src/runtime/builder.rs:122
  63: tokio_threadpool::callback::Callback::call
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/callback.rs:21
  64: tokio_threadpool::worker::Worker::do_run::{{closure}}::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:121
  65: tokio_threadpool::task::queue::Queue::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.2/src/global.rs:176
  66: crossbeam_epoch::collector::Handle::is_pinned
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  67: crossbeam_epoch::collector::Handle::is_pinned
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  68: tokio_threadpool::task::queue::Queue::poll
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.2/src/global.rs:150
  69: tokio_threadpool::worker::Worker::do_run::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:119
  70: crossbeam_epoch::collector::Handle::is_pinned
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  71: crossbeam_epoch::collector::Handle::is_pinned
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  72: tokio_threadpool::worker::Worker::do_run
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/worker/mod.rs:110
  73: tokio_threadpool::pool::Pool::spawn_thread::{{closure}}
             at /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.5/src/pool/mod.rs:417
  74: <alloc::collections::CollectionAllocErr as core::convert::From<core::alloc::AllocErr>>::from
             at /Users/travis/build/rust-lang/rust/src/libstd/sys_common/backtrace.rs:136
  75: crossbeam_epoch::collector::Handle::is_pinned
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/mod.rs:409
  76: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panic.rs:313
  77: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panicking.rs:310
  78: panic_unwind::dwarf::eh::read_encoded_pointer
             at libpanic_unwind/lib.rs:106
  79: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panicking.rs:289
  80: <tokio_threadpool::notifier::Forget<T>>::new
             at /Users/travis/build/rust-lang/rust/src/libstd/panic.rs:392
  81: crossbeam_epoch::collector::Handle::is_pinned
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/mod.rs:408
  82: crossbeam_epoch::collector::Handle::is_pinned
             at /Users/travis/build/rust-lang/rust/src/liballoc/boxed.rs:640
  83: std::sys::unix::thread::Thread::new::thread_start
             at /Users/travis/build/rust-lang/rust/src/liballoc/boxed.rs:650
             at libstd/sys_common/thread.rs:24
             at libstd/sys/unix/thread.rs:90
  84: _pthread_body
  85: _pthread_start

shepmaster avatar Jul 29 '18 14:07 shepmaster

cURL request from Chrome:

curl 'http://127.0.0.1:5000/compile' -H 'Referer: http://127.0.0.1:5000/' -H 'Origin: http://127.0.0.1:5000' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3503.0 Safari/537.36' -H 'DNT: 1' -H 'Content-Type: application/json' --data-binary '{"channel":"stable","mode":"debug","crateType":"bin","tests":false,"code":"fn main() {\n//(Box::into_raw(Box::new(0)) as usize) * 2;\n\n    let mut a: [u8; 0] = [];\n    unsafe {\n        *a.get_unchecked_mut(1) = 1;\n    }\n    \n}","target":"llvm-ir","assemblyFlavor":"att","demangleAssembly":"demangle","processAssembly":"filter","backtrace":false}' --compressed

The corresponding struct:

#[derive(Debug, Clone, Deserialize, Extract)]
struct CompileRequest {
    target: String,
    #[serde(rename = "assemblyFlavor")]
    assembly_flavor: Option<String>,
    #[serde(rename = "demangleAssembly")]
    demangle_assembly: Option<String>,
    #[serde(rename = "processAssembly")]
    process_assembly: Option<String>,
    channel: String,
    mode: String,
    #[serde(default)]
    edition: String,
    #[serde(rename = "crateType")]
    crate_type: String,
    tests: bool,
    backtrace: bool,
    code: String,
}

and the handler:

    impl Sandbox {
        /// @post("/compile")
        /// @content_type("text/plain")
        fn index(&self, body: ::CompileRequest) -> Result<String, ::Error> {

shepmaster avatar Jul 29 '18 14:07 shepmaster

https://github.com/carllerche/tower-web/blob/master/src/extract/serde.rs#L145

put without reserve.

This code should be refactored to use BufStream::collect

carllerche avatar Jul 30 '18 01:07 carllerche

This was fixed, no?

carllerche avatar Aug 04 '18 22:08 carllerche

Yes by #41, modulo writing tests as requested.

shepmaster avatar Aug 05 '18 01:08 shepmaster

Ok, I will leave this opeen.

carllerche avatar Aug 05 '18 02:08 carllerche