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

Panicked: thread 'main' panicked at 'index out of bounds: the len is 7 but the index is 7' #5775

Closed
Officeyutong opened this issue Feb 14, 2023 · 1 comment · Fixed by #5777
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@Officeyutong
Copy link

Test Case

I have made an repo to demonstrate this panic

Steps to Reproduce

  • Clone this repo
  • Run cargo run

Expected Results

No panic happens.

Actual Results

The program panicked with the following stack trace:

thread 'main' panicked at 'index out of bounds: the len is 7 but the index is 7', C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\environ\src\component\types.rs:425:9
stack backtrace:
   0:     0x7ff6907e0852 - std::backtrace_rs::backtrace::dbghelp::trace
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:98
   1:     0x7ff6907e0852 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff6907e0852 - std::sys_common::backtrace::_print_fmt
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\sys_common\backtrace.rs:65
   3:     0x7ff6907e0852 - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\sys_common\backtrace.rs:44
   4:     0x7ff6907f8acb - core::fmt::write
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\core\src\fmt\mod.rs:1208
   5:     0x7ff6907dd7da - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\io\mod.rs:1682
   6:     0x7ff6907e059b - std::sys_common::backtrace::_print
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\sys_common\backtrace.rs:47
   7:     0x7ff6907e059b - std::sys_common::backtrace::print
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\sys_common\backtrace.rs:34
   8:     0x7ff6907e2ec9 - std::panicking::default_hook::closure$1
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:267
   9:     0x7ff6907e2b4b - std::panicking::default_hook
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:286
  10:     0x7ff6907e3761 - std::panicking::rust_panic_with_hook
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:688
  11:     0x7ff6907e34ee - std::panicking::begin_panic_handler::closure$0
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:579
  12:     0x7ff6907e126f - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\sys_common\backtrace.rs:137
  13:     0x7ff6907e31a0 - std::panicking::begin_panic_handler
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:575
  14:     0x7ff6908652f5 - core::panicking::panic_fmt
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\core\src\panicking.rs:64
  15:     0x7ff690865467 - core::panicking::panic_bounds_check
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\core\src\panicking.rs:147
  16:     0x7ff6904a373d - core::slice::index::impl$2::index<enum2$<wasmtime_environ::component::types::TypeDef> >
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\core\src\slice\index.rs:260
  17:     0x7ff6903ebba0 - core::slice::index::impl$0::index
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\core\src\slice\index.rs:18
  18:     0x7ff6903ebba0 - alloc::vec::impl$15::index<enum2$<wasmtime_environ::component::types::TypeDef>,usize,alloc::alloc::Global>
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\alloc\src\vec\mod.rs:2727
  19:     0x7ff6903f02f9 - cranelift_entity::primary::impl$2::index<wasmtime_environ::component::types::ComponentTypeIndex,enum2$<wasmtime_environ::component::types::TypeDef> >
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\cranelift\entity\src\primary.rs:202
  20:     0x7ff69042fdf8 - wasmtime_environ::component::types::ComponentTypesBuilder::component_outer_type
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\environ\src\component\types.rs:425
  21:     0x7ff690430556 - wasmtime_environ::component::types::ComponentTypesBuilder::component_type_ref
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\environ\src\component\types.rs:476
  22:     0x7ff6904a8f9a - wasmtime_environ::component::translate::Translator::translate_payload
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\environ\src\component\translate.rs:486
  23:     0x7ff6904a78b0 - wasmtime_environ::component::translate::Translator::translate
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\environ\src\component\translate.rs:349
  24:     0x7ff68f91417e - wasmtime::component::component::Component::build_artifacts
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\wasmtime\src\component\component.rs:184
  25:     0x7ff68f913b26 - wasmtime::component::component::Component::from_binary
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\wasmtime\src\component\component.rs:133
  26:     0x7ff68f861768 - wasmtime::component::component::Component::new<ref$<alloc::vec::Vec<u8,alloc::alloc::Global> > >
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\wasmtime\src\component\component.rs:93
  27:     0x7ff68f8618b8 - wasmtime::component::component::Component::from_file<ref$<str$> >
                               at C:\Users\LocalUser\.cargo\git\checkouts\wasmtime-41807828cb3a7a7e\6df3bbb\crates\wasmtime\src\component\component.rs:103
  28:     0x7ff68f861586 - wasmtime_panic_reproduce::main
                               at E:\Temp\wasmtime-panic-reproduce\src\main.rs:5
  29:     0x7ff68f861d7b - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\core\src\ops\function.rs:507
  30:     0x7ff68f8612ce - std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\std\src\sys_common\backtrace.rs:121
  31:     0x7ff68f8612ce - std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\std\src\sys_common\backtrace.rs:121
  32:     0x7ff68f861061 - std::rt::lang_start::closure$0<tuple$<> >
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\std\src\rt.rs:166
  33:     0x7ff6907d931e - core::ops::function::impls::impl$2::call_once
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\core\src\ops\function.rs:606
  34:     0x7ff6907d931e - std::panicking::try::do_call
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:483
  35:     0x7ff6907d931e - std::panicking::try
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:447
  36:     0x7ff6907d931e - std::panic::catch_unwind
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panic.rs:137
  37:     0x7ff6907d931e - std::rt::lang_start_internal::closure$2
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\rt.rs:148
  38:     0x7ff6907d931e - std::panicking::try::do_call
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:483
  39:     0x7ff6907d931e - std::panicking::try
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panicking.rs:447
  40:     0x7ff6907d931e - std::panic::catch_unwind
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\panic.rs:137
  41:     0x7ff6907d931e - std::rt::lang_start_internal
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library\std\src\rt.rs:148
  42:     0x7ff68f86103a - std::rt::lang_start<tuple$<> >
                               at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405\library\std\src\rt.rs:165
  43:     0x7ff68f861659 - main
  44:     0x7ff69086331c - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  45:     0x7ff69086331c - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  46:     0x7ffd19827614 - BaseThreadInitThunk
  47:     0x7ffd1a2626a1 - RtlUserThreadStart

Versions and Environment

Wasmtime version or commit: 6df3bbb, with features component-model

Operating system: Windows 10 21H2, 19044.2486

Architecture: x64

Rustc: rustc 1.67.0 (fc594f156 2023-01-24)

Cargo: cargo 1.67.0 (8ecd4f20a 2023-01-10)

@Officeyutong Officeyutong added the bug Incorrect behavior in the current implementation that needs fixing label Feb 14, 2023
alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Feb 14, 2023
This commit fixes a panic related to type imports where an import of a
type didn't correctly declare the new type index on the Wasmtime side of
things. Additionally this plumbs more support throughout Wasmtime to
support type imports, namely that they do not need to be supplied
through a `Linker`. This additionally implements a feature where empty
instances, even transitively, do not need to be supplied by a Wasmtime
embedder. This means that instances which only have types, for example,
do not need to be supplied into a `Linker` since no runtime information
for them is required anyway.

Closes bytecodealliance#5775
@alexcrichton
Copy link
Member

Thanks for the report! I've posted a fix for this at #5777

Type imports/exports were unfortunately underbaked a bit when I first implemented components in Wasmtime and as we fleshed them out for the bindings story I hadn't gotten a chance to come back to Wasmtime and fill out the implementation, so the bug reports are appreciated!

alexcrichton added a commit that referenced this issue Feb 14, 2023
This commit fixes a panic related to type imports where an import of a
type didn't correctly declare the new type index on the Wasmtime side of
things. Additionally this plumbs more support throughout Wasmtime to
support type imports, namely that they do not need to be supplied
through a `Linker`. This additionally implements a feature where empty
instances, even transitively, do not need to be supplied by a Wasmtime
embedder. This means that instances which only have types, for example,
do not need to be supplied into a `Linker` since no runtime information
for them is required anyway.

Closes #5775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants