-
Notifications
You must be signed in to change notification settings - Fork 998
Description
While understanding how wasm locals get marked during GC, I found this case where they don't seem to get marked causing heap corruption of valid objects.
Using latest dev tinygo
https://github.com/anuraaga/tinygo-gctest
git clone https://github.com/anuraaga/tinygo-gctest
cd tinygo-gctest
tinygo build -scheduler=none -target=wasi -o gctest.wasm .
go run github.com/tetratelabs/wazero/cmd/wazero@latest run gctest.wasm
Should print yogi and garfield, but prints garfield twice because yogi got overwritten.
Definitely not an expert of the code, but looking at gc.go my reading is it creates stack slots for functions with a call to runtime.alloc inside them, but doesn't seem to ever go up the call tree from these. In this example, the pointer is returned to the calling function, which itself has no direct call to runtime.alloc, but keeps the pointer in one of its wasm slots and would need a GC stack slot allocated for it. Not sure how to update the code to do this if it's missing, but hopefully it's not too hard 😂