Skip to content

GetURI causes runtime segfault #92

@skosch

Description

@skosch

Hi there! [I hope I am posting this in the right place; please forgive my ignorance about the Go/WASM ecosystem.]

I am using http-wasm via this Traefik OIDC auth plugin. The plugin calls req.GetURI() in its request handler.

Occasionally, some request crashes the runtime, which I can only fix by restarting Traefik. Unfortunately I haven't been able to isolate a specific example URI. The plugin is written using http-wasm-guest-tinygo, which calls GetURI via GetString. The latter then fails like:

func GetString(fn func(ptr uint32, limit imports.BufLimit) (len uint32)) (result string) {
	size := fn(ReadBufPtr, ReadBufLimit)
	if size == 0 {
		return // If nothing was read, return an empty string.
	} else if size <= ReadBufLimit {
		return string(ReadBuf[:size]) // string will copy the buffer.  <-------  THIS FAILS!
	}
	...
}

I would be grateful for any pointers.

The full stacktrace:

runtime stack:

runtime.throw({0xab3e1, 0x2a})
	/home/runner/sdk/gotip/src/runtime/panic.go:1074 +0x3 fp=0x48c1d8 sp=0x48c1b0 pc=0x14a00003
runtime.sigpanic()
	/home/runner/sdk/gotip/src/runtime/os_wasm.go:26 +0xe fp=0x48c1f8 sp=0x48c1d8 pc=0x121a000e
runtime.mallocgcSmallNoscan(0x22, 0x0, 0x0)
	/home/runner/sdk/gotip/src/runtime/malloc.go:1267 +0x26 fp=0x48c250 sp=0x48c1f8 pc=0x10970026
runtime.mallocgc(0x22, 0x0, 0x0)
	/home/runner/sdk/gotip/src/runtime/malloc.go:1046 +0x17 fp=0x48c288 sp=0x48c250 pc=0x14660017
runtime.slicebytetostring(0x0, 0x86a000, 0x22)
	/home/runner/sdk/gotip/src/runtime/string.go:156 +0xb fp=0x48c2b8 sp=0x48c288 pc=0x1339000b
github.com/http-wasm/http-wasm-guest-tinygo/handler/internal/mem.GetString(0xb8a00)
	/home/runner/go/pkg/mod/github.com/traefik/http-wasm-guest-tinygo@v0.0.0-20240913140402-af96219ffea5/handler/internal/mem/mem.go:44 +0x8 fp=0x48c310 sp=0x48c2b8 pc=0x26c80008
github.com/http-wasm/http-wasm-guest-tinygo/handler.wasmRequest.GetURI(...)
	/home/runner/go/pkg/mod/github.com/traefik/http-wasm-guest-tinygo@v0.0.0-20240913140402-af96219ffea5/handler/request.go:31
github.com/http-wasm/http-wasm-guest-tinygo/handler.(*wasmRequest).GetURI(0x482a60)
	<autogenerated>:1 +0x5 fp=0x48c330 sp=0x48c310 pc=0x26e90005
main.(*TraefikOIDCWasm).handleRequest(0x8607c0, {0x114ef8, 0x482a60}, {0x1142d0, 0x482a60})
	/home/runner/work/traefik-oidc-wasm/traefik-oidc-wasm/main.go:107 +0xd fp=0x48c388 sp=0x48c330 pc=0x274e000d
...

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