-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[lightbeam] panicked at index out of bound in func_type_index (module.rs) #722
Comments
Shouldn't at this point the fed Wasm already be validated by the parser (probably |
This module is valid actually: $ wasm-validate index_oob_func_type.wasm && echo success
success Same result for |
Ah ok. I am not sure if the proposed solutions would actually "fix" the bug:
Because we should normally only return errors for invalid input or input that requires Wasm features we do not yet support. For everything else we probably have a bug that we should either fix or gracefully abort the process and report the issue which we do already by the index-out-of-bounds panic. Also for the sake of compiler performance we should not check something that we should assume to be true due to given invariances. |
For me it's a runtime error. For example, this specific case is checked in wasmtime/crates/lightbeam/src/module.rs Lines 185 to 190 in 77bf768
|
True, but I guess at this point only @Vurich is capable of properly answering this because this goes into the Lightbeam implementation details now. |
|
This feels like something that should be trivial to find a reduced testcase for, which might be more enlightening about it. Right now to debug this we'd have to basically just look at the code and work out what could be the issue from first principles, and we won't be sure that this testcase passing would actually mean the bug is fixed. We could do that but I feel like making a reduced testcase for this should be easy, I can't see it being a complex bug. |
Here is a minimized testcase: (module
(type (;0;) (func))
(type (;1;) (func (param i32) (result i32)))
(import "env" "b" (func (;0;) (type 0)))
(import "env" "c" (func (;1;) (type 0)))
(import "env" "d" (func (;2;) (type 0)))
(import "env" "e" (func (;3;) (type 0)))
(import "env" "f" (func (;4;) (type 0)))
(import "env" "g" (func (;5;) (type 0)))
(import "env" "h" (func (;6;) (type 0)))
(import "env" "i" (func (;7;) (type 0)))
(import "env" "j" (func (;8;) (type 0)))
(func (;9;) (type 1) (param i32) (result i32)
call 10
i32.const 9)
(func (;10;) (type 0)
unreachable)
(export "_start" (func 9))
) After execution, we get the following error: thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 10', /rustc/2d1a551e144335e0d60a637d12f410cf65849876/src/libcore/slice/mod.rs:2704:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. So, i suppose that the issue is because imported functions are not added to the list all callable functions. |
Are imports generally already processed at all? |
Yes exactly. |
This is for the local test running harness, which is essentially cruft that I haven't removed yet because it would require porting the Lightbeam test cases into Wasmtime test cases. These (i.e. globals, exports etc) should be handled by Wasmtime, which is why you don't see that code there. The original bug does appear to be in Lightbeam, however. |
Issue description
When calling the
translate
function of lightbeam, an index out of bound error occurs in functionfunc_type_index
because argumentfunc_idx
is not checked.wasmtime/crates/lightbeam/src/module.rs
Lines 395 to 397 in 77bf768
This function is called when handling
WasmOperator::Call
:wasmtime/crates/lightbeam/src/microwasm.rs
Lines 1165 to 1168 in 77bf768
Fix proposal
2 potentials solutions:
func_index
is in the range insidefunc_type_index
function otherwise return an Error.func_index
is in the range each time before callingfunc_type_index
andfunc_type
functions.Reproduction
wasmtime commit: 77bf768
Download
index_oob_func_type.zip
Just create a basic testing program calling lightbeam
translate
:RUST_BACKTRACE
The text was updated successfully, but these errors were encountered: