rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript

Home Page:https://rustwasm.github.io/docs/wasm-bindgen/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"memory access out of bounds" on allocating large structs.

karikera opened this issue · comments

Describe the Bug

memory access out of bounds on allocating large structs.

runtime error

wasm-bindgen@0.2.92

Steps to Reproduce

#[wasm_bindgen]
pub struct FoobarPass {
    buf:[i32; 1024*512],
}

#[wasm_bindgen]
pub fn foobar_pass()->FoobarPass { // it's okay
    FoobarPass{
        buf: [0; 1024*512],
    }
}

#[wasm_bindgen]
pub struct FoobarFail {
    buf:[i32; 1024*256],
    n:i64,
}

#[wasm_bindgen]
pub fn foobar_fail()->FoobarFail { // it fails
    FoobarFail{
        buf: [0; 1024*256],
        n:0,
    }
}

Expected Behavior

no error

Actual Behavior

Uncaught RuntimeError RuntimeError: memory access out of bounds