Panic at compilation in wasm with optimization flag
nikpivkin opened this issue · 1 comments
nikpivkin commented
Short description
I tried to compile the policy in WASM with the optimize
> 0 flag, but it caused a panic.
Steps To Reproduce
❯ cat <<EOF > example.rego
package test
import rego.v1
deny if true
EOF
❯ opa build -t wasm -e test/deny example.rego -O 1
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
github.com/open-policy-agent/opa/internal/compiler/wasm.(*Compiler).fileAddr(...)
github.com/open-policy-agent/opa/internal/compiler/wasm/wasm.go:1658
github.com/open-policy-agent/opa/internal/compiler/wasm.(*Compiler).runtimeErrorAbort(0x14000000ea0?, {0x0, 0x0, 0x0, {0x0, 0x0}, {0x0, 0x0}}, 0x140000c2ee0?)
github.com/open-policy-agent/opa/internal/compiler/wasm/wasm.go:1750 +0x22c
github.com/open-policy-agent/opa/internal/compiler/wasm.(*Compiler).compileBlock(0x14000000ea0, 0x140000c3420?)
github.com/open-policy-agent/opa/internal/compiler/wasm/wasm.go:1048 +0x2490
github.com/open-policy-agent/opa/internal/compiler/wasm.(*Compiler).compileFunc(0x14000000ea0, 0x1400043e600)
github.com/open-policy-agent/opa/internal/compiler/wasm/wasm.go:856 +0x70c
github.com/open-policy-agent/opa/internal/compiler/wasm.(*Compiler).compileFuncs(0x14000000ea0)
github.com/open-policy-agent/opa/internal/compiler/wasm/wasm.go:718 +0x70
github.com/open-policy-agent/opa/internal/compiler/wasm.(*Compiler).Compile(0x14000000ea0)
github.com/open-policy-agent/opa/internal/compiler/wasm/wasm.go:312 +0x60
github.com/open-policy-agent/opa/compile.(*Compiler).compileWasm(0x14000342000, {0x1039198e8, 0x10428c7c0})
github.com/open-policy-agent/opa/compile/compile.go:713 +0x188
github.com/open-policy-agent/opa/compile.(*Compiler).Build(0x14000342000, {0x1039198e8, 0x10428c7c0})
github.com/open-policy-agent/opa/compile/compile.go:348 +0x13c
github.com/open-policy-agent/opa/cmd.dobuild({0x14000382dc8, 0x140004c6600, 0x0, 0x0, 0x1, {{0x1400042c920, 0x1, 0x1}, 0x1}, {0x103108372, ...}, ...}, ...)
github.com/open-policy-agent/opa/cmd/build.go:337 +0x800
github.com/open-policy-agent/opa/cmd.init.1.func2(0x140003eec00?, {0x140003681c0?, 0x4?, 0x1030fe0d8?})
github.com/open-policy-agent/opa/cmd/build.go:228 +0x50
github.com/spf13/cobra.(*Command).execute(0x140003fc608, {0x140003680e0, 0x7, 0x7})
github.com/spf13/cobra@v1.8.1/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x104249fc0)
github.com/spf13/cobra@v1.8.1/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(0x1041300a8?)
github.com/spf13/cobra@v1.8.1/command.go:1041 +0x1c
main.main()
github.com/open-policy-agent/opa/main.go:14 +0x24
Expected behavior
build without panic
Additional context
opa version
Version: 0.70.0
Build Commit:
Build Timestamp:
Build Hostname:
Go Version: go1.23.2
Platform: darwin/arm64
WebAssembly: unavailable