Skip to content
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

experimental: reflect custom allocated buffer capacity to internal buffer #2189

Merged
merged 3 commits into from
Apr 17, 2024

Conversation

anuraaga
Copy link
Contributor

/cc @ncruces

When trying to use the custom allocator interface, I was getting crashes since the capacity wasn't being applied to the internal m.Buffer itself

 [recovered]
	panic: runtime error: slice bounds out of range [::266304] with capacity 196608 (recovered by wazero)
wasm stack trace:
	wasi_snapshot_preview1.fd_write(i32,i32,i32,i32) i32
	.$21(i32,i32,i32) i32
	.$22(i32,i32,i32) i32
	.$31(i32,i32,i32)
	.$787(i32)
	.$783(i32,i32,i32)
	.$806(i32,i32,i32) i32

Go runtime stack trace:
goroutine 37 [running]:
runtime/debug.Stack()
	/opt/homebrew/Cellar/go/1.22.2/libexec/src/runtime/debug/stack.go:24 +0x6c
github.com/tetratelabs/wazero/internal/wasmdebug.(*stackTrace).FromRecovered(0xc000a0c798, {0x101482be0, 0xc000212048})
	/Users/anuraag/go/pkg/mod/github.com/tetratelabs/wazero@v1.7.1/internal/wasmdebug/debug.go:139 +0x1a8
github.com/tetratelabs/wazero/internal/engine/wazevo.(*callEngine).callWithStack.func1()
	/Users/anuraag/go/pkg/mod/github.com/tetratelabs/wazero@v1.7.1/internal/engine/wazevo/call_engine.go:256 +0x4b0
panic({0x101482be0?, 0xc000212048?})
	/opt/homebrew/Cellar/go/1.22.2/libexec/src/runtime/panic.go:770 +0x124
github.com/tetratelabs/wazero/internal/wasm.(*MemoryInstance).Read(0xc00013c7e0, 0x41030, 0x10)
	/Users/anuraag/go/pkg/mod/github.com/tetratelabs/wazero@v1.7.1/internal/wasm/memory.go:160 +0x104
github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1.writev({0x1014aedd0, 0xc00013c7e0}, 0x41030, 0x2, 0xc00002ece8)

…ffer

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
@anuraaga anuraaga force-pushed the experimental-buffer-updatecap branch from 33ffa23 to 5441eac Compare April 17, 2024 02:44
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Copy link
Collaborator

@ncruces ncruces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! How did I miss this? Sorry this got to 1.7.1.

As a mitigation, while this is unreleased, I think your allocator can use fixed capacity.

Mine doesn't because bytes beyond len haven't been committed, and segfault if accessed, but this happens only if manually resliced, or if Wasm would access beyond len, neither of which should happen.

internal/wasm/memory_test.go Outdated Show resolved Hide resolved
internal/wasm/memory.go Show resolved Hide resolved
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
@mathetake mathetake merged commit 5a9cb5a into tetratelabs:main Apr 17, 2024
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants