-
Notifications
You must be signed in to change notification settings - Fork 59
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
Inserting large structure in to HashMap causes "memory access out of bounds" #246
Comments
OP was also able to replicate this with Box, so this is likely unrelated to HashMap itself. They posted this earlier in Discord: //const LARGE_STRUCT_SIZE: usize = 87333; // This is the largest I can create the object without any issues
const LARGE_STRUCT_SIZE: usize = 87334;
struct LargeStruct {
values: [u8; LARGE_STRUCT_SIZE]
}
fn main() {
let ls = LargeStruct { values: [0; LARGE_STRUCT_SIZE] };
let mut hm = Box::new(ls);
} (May need stdweb) |
This sounds like maybe a bug in the dlmalloc wasm port. Would be interested in knowing if this also reproduces with +cc @alexcrichton |
This also happens with wee_alloc. |
This sounds like it's likely related to the stack size being too slow and we're probably seeing a stack overflow here. Large structs like this are copied around the stack a bunch of times, especially in debug mode. Are these examples compiled in debug mode? Is it possible to see the faulting instruction and maybe see if the global stack pointer is less than zero at that point? |
Can't reproduce this. I took the code from this comment. Then I compiled it with this command and launched with this js snippet from node: const fs = require('fs');
const buffer = fs.readFileSync('main.wasm');
let m = new WebAssembly.Module(buffer);
let instance = new WebAssembly.Instance(m, {});
instance.exports.main(); I tried both stable and nightly and both with opts and without. However, I can reproduce this with the original one. I have this stack trace:
Quick inspection of a resulting wasm shows that Update: Here is the listing of what I'm getting, and here is the line where it is crashing. Update: The load is happening with negative address: -84 |
@pepyakin I believe when I was testing the issue with Edit: I only tested |
No worries @NathanFlurry ! I can confirm that this is the regular stack overflow. -84 is value that is derived from the stack pointer. Here are stack frame sizes that I can see: crash_wasm - 262192 which is totaling: 1179792 bytes |
Great! Before we close the issue, is there a way to see the default stack size for wasm targets? Right now I'm trying something like this with no success:
I saw this commit which shouldn't override whatever stack size I pass, am I missing something? |
@NathanFlurry there's currently no API to see the default stack size, but a recent PR was targeted at allowing the exact invocation you had above to set the stack size. It was a mistake that doesn't work! |
When attempting to insert a large structure in to a
HashMap
with thewasm32-unknown-unknown
target, I get this error:This code produces the error:
Rust:
JavaScript:
Build script:
The
LARGE_STRUCTURE_SIZE
cutoff is somewhere between 65536 to 131072 bytes; I get different values with and without stdweb. I've tried this with wee_alloc also with no success.The text was updated successfully, but these errors were encountered: