Stream: git-wasmtime

Topic: wasmtime / Issue #2430 out of bounds memory access


view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 08:39):

ZW007 opened Issue #2430:

I am running a standalone wasm file by using wasmtime --dir=. mainWasi.wasm
The wasm needs to read some local files, the size of local files in total is 10MB

Error: failed to run main module mainWasi.wasm

Caused by:
0: failed to invoke command default
1: wasm trap: out of bounds memory access
wasm backtrace:
0: 0x29cb - <unknown>!Predict
1: 0x346d - <unknown>!testing
2: 0x38ef - <unknown>!foo
3: 0x39eb - <unknown>!__original_main
4: 0x2c1 - <unknown>!_start

I wonder if I can allocate more memory for wasmtime? In lucet, i can use --min-reserved-size, but haven't found similar in wasmtime

Thank you!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 09:36):

ZW007 edited Issue #2430:

I am running a standalone wasm file by using wasmtime --dir=. mainWasi.wasm
The wasm needs to read some local files, the size of local files in total is 10MB

Error: failed to run main module mainWasi.wasm

Caused by:
0: failed to invoke command default
1: wasm trap: out of bounds memory access
wasm backtrace:
0: 0x29cb - <unknown>!Predict
1: 0x346d - <unknown>!testing
2: 0x38ef - <unknown>!foo
3: 0x39eb - <unknown>!__original_main
4: 0x2c1 - <unknown>!_start

I wonder if I can allocate more memory for wasmtime? In lucet, i can use --min-reserved-size, but haven't found similar in wasmtime, but even when i use lucetc-wasi --min-reserved-size 6442450944 -o mainLucet.so mainWasi.wasm in lucet, I still get the error thread 'main' panicked at 'instance can be created: ModuleError(IncorrectModule("heap spec sizes would overflow: HeapSpec { reserved_size: 6442450944, guard_size: 4194304, initial_size: 131072, max_size: None }"))', lucet-wasi/src/main.rs:239:24

What I am running is a standalone lenet inference task. I dont think it can be called a large app. Maybe I should try to read just one image from the file system, rather than the whole t10k-images-idx3-ubyte which is 7.8MB.

Thank you!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 09:38):

ZW007 edited Issue #2430:

I am running a standalone wasm file by using wasmtime --dir=. mainWasi.wasm
The wasm needs to read some local files, the size of local files in total is 10MB

Error: failed to run main module mainWasi.wasm

Caused by:
0: failed to invoke command default
1: wasm trap: out of bounds memory access
wasm backtrace:
0: 0x29cb - <unknown>!Predict
1: 0x346d - <unknown>!testing
2: 0x38ef - <unknown>!foo
3: 0x39eb - <unknown>!__original_main
4: 0x2c1 - <unknown>!_start

I wonder if I can allocate more memory for wasmtime? In lucet, i can use --min-reserved-size, but haven't found similar in wasmtime, but even when i use lucetc-wasi --min-reserved-size 6442450944 -o mainLucet.so mainWasi.wasm to compile in lucet, I still get the error in lucet run: thread 'main' panicked at 'instance can be created: ModuleError(IncorrectModule("heap spec sizes would overflow: HeapSpec { reserved_size: 6442450944, guard_size: 4194304, initial_size: 131072, max_size: None }"))', lucet-wasi/src/main.rs:239:24

What I am running is a standalone lenet inference task. I dont think it can be called a large app. Maybe I should try to read just one image from the file system, rather than the whole t10k-images-idx3-ubyte which is 7.8MB.

Thank you!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 16:15):

alexcrichton commented on Issue #2430:

I think this is probably unrelated to the memory limits for the wasm module but rather this looks like a "segfault" in the wasm module itself where it's reading/writing memory out of bounds. Are you sure though this is related to memory allocation?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 16:24):

ZW007 commented on Issue #2430:

I think this is probably unrelated to the memory limits for the wasm module but rather this looks like a "segfault" in the wasm module itself where it's reading/writing memory out of bounds. Are you sure though this is related to memory allocation?

@alexcrichton I do not think there is a problem of the wasm module itself. I have tried emcc and nodejs, the LeNet dnn reference task works fine: (I have to allow_memory_growth to make it work, and I also use --embed-file so that nodejs can access local file: model and image file)
emcc -s ALLOW_MEMORY_GROWTH=1 --embed-file ./ -I ./ main.c lenet.c -lm -o

In wasmtime, I did
wasm32-wasi-clang -I ./ lenet.c main.c -lm -o mainWasi.wasm
Then I run with
wasmtime --dir=. mainWasi.wasm
Maybe is the file I read too large, (around 10MB), so i need somehow more space?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 16:30):

alexcrichton commented on Issue #2430:

I'd recommend going from the backtrace and looking in the wasm module, for example in the wasm file what instruction is at offset 0x29cb in the Predict function? Is that a memory allocation function or just a normal load/store? If it's the latter then this is likely a bug with the wasm module itself.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 17:01):

ZW007 commented on Issue #2430:

I'd recommend going from the backtrace and looking in the wasm module, for example in the wasm file what instruction is at offset 0x29cb in the Predict function? Is that a memory allocation function or just a normal load/store? If it's the latter then this is likely a bug with the wasm module itself.

@alexcrichton Thank you Alex, but I dont know how can I debug and trace in wasmtime (. There is no access to the local file in Predict function, because it was done before that, Predict(lenet, test_data[i], 10); where lenet and test_date[] are model and image that has been loaded from local file.
The main.c called Predict function:
https://github.com/ZW007/lenet5/blob/245d95cdc141eb46fc5e58193e239f8cb8245e15/main.c#L46
Here is Predict() function:
https://github.com/ZW007/lenet5/blob/6b60eb9fd8233e4503c5ff9b637229810ec4b719/lenet.c#L269
And in Predict(), we have:
https://github.com/ZW007/lenet5/blob/6b60eb9fd8233e4503c5ff9b637229810ec4b719/lenet.c#L150

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 18:41):

ZW007 edited a comment on Issue #2430:

I'd recommend going from the backtrace and looking in the wasm module, for example in the wasm file what instruction is at offset 0x29cb in the Predict function? Is that a memory allocation function or just a normal load/store? If it's the latter then this is likely a bug with the wasm module itself.

@alexcrichton Thank you Alex, but I dont know how can I debug and trace in wasmtime (. There is no access to the local file in Predict function, because it was done before that, Predict(lenet, test_data[i], 10); where lenet and test_date[] are model and image that has been loaded from local file.
The main.c called Predict function:
https://github.com/ZW007/lenet5/blob/245d95cdc141eb46fc5e58193e239f8cb8245e15/main.c#L46
Here is Predict() function:
https://github.com/ZW007/lenet5/blob/6b60eb9fd8233e4503c5ff9b637229810ec4b719/lenet.c#L269
And in Predict(), we have:
https://github.com/ZW007/lenet5/blob/6b60eb9fd8233e4503c5ff9b637229810ec4b719/lenet.c#L150

Did you mean by looking up wabt format of my wasm module
There are many i32.load or i32.store offset, but no one is 0x29cb

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 18:46):

ZW007 commented on Issue #2430:

wasm module
https://github.com/ZW007/lenet5/blob/45d809876f4b9b707cf992b80576f1b41cb69c3b/mainWasi.wat#L4028

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2020 at 18:48):

ZW007 edited a comment on Issue #2430:

@alexcrichton wasm module
https://github.com/ZW007/lenet5/blob/45d809876f4b9b707cf992b80576f1b41cb69c3b/mainWasi.wat#L4028

view this post on Zulip Wasmtime GitHub notifications bot (Nov 20 2020 at 04:10):

ZW007 commented on Issue #2430:

I tested a new lenet5 code, again, it works fine for nodejs and emscripten, but not wasmtime. This time, code is similar, and I also use the command
wasm32-wasi-clang -I ./ mat.c net.c -lm -o net.wasm
wasmtime --dir=. net.wasm
But, I got a different error, not out of bounds memory access error, but a unreachable (
I was wondering if this could also be caused by module itself @alexcrichton

Error: failed to run main module net.wasm

Caused by:
0: failed to invoke command default
1: wasm trap: unreachable
wasm backtrace:
0: 0x1f3 - <unknown>!unreachable:main
1: 0x25d8 - <unknown>!__main_argc_argv
2: 0x2654 - <unknown>!__main_void
3: 0x26bc - <unknown>!__original_main
4: 0x1ff - <unknown>!_start


Last updated: Dec 23 2024 at 12:05 UTC