bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.32k stars 1.29k forks source link

thread '<unnamed>' panicked at 'index out of bounds while running php-worker.wasm #4865

Closed kenorb closed 2 years ago

kenorb commented 2 years ago
$ wget https://github.com/oraoto/pib/raw/master/docs/php-worker.wasm
$ wasmtime php-worker.wasm -- --version
thread '<unnamed>' panicked at 'index out of bounds: the len is 2097152 but the index is 2097152', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.1.2/src/lib.rs:193:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ wasmtime --version
wasmtime-cli 0.37.0

Full backtrace:

$ RUST_BACKTRACE=1 wasmtime php-worker.wasm -- --version
thread '<unnamed>' panicked at 'index out of bounds: the len is 2097152 but the index is 2097152', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.1.2/src/lib.rs:193:17
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::panicking::panic_bounds_check
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:84:5
   3: cranelift_codegen::machinst::lower::alloc_vregs
   4: cranelift_codegen::machinst::lower::Lower<I>::lower
   5: cranelift_codegen::machinst::compile::compile
   6: <cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function
   7: cranelift_codegen::context::Context::compile
   8: cranelift_codegen::context::Context::compile_and_emit
   9: <wasmtime_cranelift::compiler::Compiler as wasmtime_environ::compilation::Compiler>::compile_function
  10: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
  11: rayon::iter::plumbing::bridge_producer_consumer::helper
  12: std::panicking::try
  13: rayon_core::registry::in_worker
  14: rayon::iter::plumbing::bridge_producer_consumer::helper
  15: std::panicking::try
  16: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  17: rayon_core::registry::WorkerThread::wait_until_cold
  18: rayon_core::registry::in_worker
  19: rayon::iter::plumbing::bridge_producer_consumer::helper
  20: std::panicking::try
  21: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  22: rayon_core::registry::WorkerThread::wait_until_cold
  23: rayon_core::registry::in_worker
  24: rayon::iter::plumbing::bridge_producer_consumer::helper
  25: std::panicking::try
  26: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  27: rayon_core::registry::WorkerThread::wait_until_cold
  28: rayon_core::registry::in_worker
  29: rayon::iter::plumbing::bridge_producer_consumer::helper
  30: std::panicking::try
  31: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  32: rayon_core::registry::WorkerThread::wait_until_cold
  33: rayon_core::registry::in_worker
  34: rayon::iter::plumbing::bridge_producer_consumer::helper
  35: rayon_core::job::StackJob<L,F,R>::run_inline
  36: rayon_core::registry::in_worker
  37: rayon::iter::plumbing::bridge_producer_consumer::helper
  38: rayon_core::job::StackJob<L,F,R>::run_inline
  39: rayon_core::registry::in_worker
  40: rayon::iter::plumbing::bridge_producer_consumer::helper
  41: std::panicking::try
  42: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  43: rayon_core::registry::WorkerThread::wait_until_cold
  44: rayon_core::registry::in_worker
  45: rayon::iter::plumbing::bridge_producer_consumer::helper
  46: std::panicking::try
  47: rayon_core::registry::in_worker
  48: rayon::iter::plumbing::bridge_producer_consumer::helper
  49: std::panicking::try
  50: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  51: rayon_core::registry::WorkerThread::wait_until_cold
  52: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Any ideas why this crashes? Is is a problem with the wasm file or wasmtime?

bjorn3 commented 2 years ago

You are using wasmtime 0.37. The latest released version is 0.40.1. Can you check if it is fixed with 0.40.1?

kenorb commented 2 years ago

Thanks for suggestion. I've updated to 0.40.1, same error.

$ wasmtime --version
wasmtime-cli 0.40.1
$ wasmtime php-worker.wasm -- --version
thread '<unnamed>' panicked at 'index out of bounds: the len is 2097152 but the index is 2097152', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/regalloc2-0.3.2/src/lib.rs:270:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
yuyang-ok commented 2 years ago

look like the compilation unit is too big.

alexcrichton commented 2 years ago

This is a slightly minimized input, but I believe that @yuyang-ok is right in that this input is seemingly too large for regalloc2. Presuming that this isn't easy to fix within regalloc2 (cc @cfallin) we will want a better error for this, so one thing we could try to do is limit the number of instructions per function. I'm not sure if browsers do that already to draw inspiration from.

cfallin commented 2 years ago

It almost certainly is a too-large function indeed; there is a limit of 2M vregs due to performance-critical bitpacking tricks. Will take a closer look tomorrow when I’m back at a computer!