You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
buffer+len native param: Uint8Array view over an ArrayBuffer resolves to the wrong data pointer (silent corruption; standalone arrays fine) #6515
When a buffer+len native-library param receives a Uint8Array view over an existing ArrayBuffer, the lowered data_ptr points at the wrong memory. The length resolves correctly, so the callee happily reads/writes len bytes — of the wrong buffer. No error, no null: silent data corruption.
A Uint8Array that owns its storage (new Uint8Array(64)) works correctly.
#[no_mangle]pubunsafeextern"C"fnjs_demo_fill(_h:i64,_off:f64,_size:f64,out:*constu8,out_len:usize) -> f64{// fill `out_len` bytes with a known pattern
std::ptr::write_bytes(out as*mutu8,0xAB, out_len);
out_len asf64}
TypeScript:
// A) standalone Uint8Array — WORKSconststandalone=newUint8Array(64);demoFill(h,0,64,standalone);console.log(standalone[0]);// 0xAB ✓// B) view over an ArrayBuffer — SILENTLY WRONGconstab=newArrayBuffer(64);constview=newUint8Array(ab);demoFill(h,0,64,view);console.log(view[0]);// 0 ✗ (callee reported 64 bytes written)
Observed with the real @perryts/webgpu binding (js_webgpu_buffer_read_mapped_into, js_webgpu_queue_write_buffer):
Note n=64 in both cases — js_native_abi_check_buffer_byte_len gets the view's length right, so it's specifically js_native_abi_check_buffer_data_ptr that mis-resolves the view (presumably resolving the view object rather than buffer + byteOffset, or failing the registered-buffer lookup and falling back to a bogus pointer).
Why it matters
Views are the normal shape for GPU/binary work — new Uint8Array(f32.buffer, off, len) is how you hand float data to a byte-oriented API, and it's what every WebGPU/three.js-style upload path produces. The failure is silent and far from its cause: we chased "why is my render black" for hours before it reduced to this.
Suggested: js_native_abi_check_buffer_data_ptr should resolve views to storage + byteOffset; if a view genuinely can't be resolved, return null so the callee's null-check fires instead of writing to the wrong place.
Found while bringing up browser-style WebGPU (three.js WebGPURenderer target) on perry. Related: #6486.
Activity
harden(runtime): validate full view span against backing in resolve_d…
fix(runtime): resolve Uint8Array-view data pointer to backing for nat…
fix(runtime): make a DataView read the backing store, not its constru…