Skip to content

syscall/js.stringVal receives negative value as an arg #4763

@egawata

Description

@egawata

I encountered an error with DataView while developing WebAssembly app.
This is a message in DevTool's Console tab of Chrome browser.

wasm_exec.js:236 Uncaught RangeError: Start offset -2093352176 is outside the bounds of the buffer
    at new DataView (<anonymous>)
    at loadString (wasm_exec.js:236:27)
    at syscall/js.stringVal (wasm_exec.js:313:17)
    at main.syscall/js.ValueOf (wasm.wasm:0x12a21)
    at main.(:8088/syscall/js.Value).Set (http://localhost:8088/wasm.wasm)
    at main.(:8088/*main.hoge).incr$bound (http://localhost:8088/wasm.wasm)
    at main.runtime.resume$1 (wasm.wasm:0xe268)
    at main.runtime.resume$1$gowrapper (wasm.wasm:0x94af)
    at main.tinygo_launch (wasm.wasm:0x4e8)
    at main.runtime.scheduler (wasm.wasm:0x95b4)

Environment

  • OS: macOS Sequoia 15.3.1
  • go version go1.23.1 darwin/arm64
  • Google Chrome 133.0.6943.142(Official Build) (arm64)
$ tinygo version
tinygo version 0.36.0-dev-056394e2 darwin/arm64 (using go version go1.23.1 and LLVM version 19.1.7)

To reproduce the error

Assuming using Chrome web browser.

# Build
cp "$(tinygo env TINYGOROOT)/targets/wasm_exec.js" ./wasm_exec.js
GOOS=js GOARCH=wasm tinygo build -o wasm.wasm ./main.go

# Run HTTP Server
go run localserver/server.go
  • Open http://localhost:8088 on your browser.
  • Open DevTools and switch to Console tab.
  • Push Run Button several times.
  • After pushing button 22 times or so, an error message like the above will appear.

Maybe the amount of memory exceeds upper limit of int32 (2_147_483_648 bytes), and value_ptr in the first arg of syscall/js.stringVal becomes negative (unexpected) value.

One solution is to convert the value to unsigned. It solved the problem in my environment.

#4764

cf. misc/wasm: make sure sp is unsigned · golang/go@9848e93

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions