Request: Switch released builds to use stdlib for RE?
- Dominant language
- Go
- Stars
- 29.3k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Description
Currently, it seems like goreleaser (and the released binaries) still does not use stdlib for RE:
https://github.com/gitleaks/gitleaks/blob/b66ac75e4fa93d86d78fccd6e2f36d2c0698b2a2/.goreleaser.yml#L18-L21
although this PR intends to make it the default: https://github.com/gitleaks/gitleaks/pull/1798
**Are you open to make stdlib the default in released binaries? Or publish additional binaries that uses stdlib?**
### Context
We run gitleaks `8.30.0` inside [nsjail](https://github.com/google/nsjail/) with memory limits. The binary immediately panics trying to allocate 4GB of memory and crashes as follows:
```
panic: allocator_unix: failed to reserve memory: cannot allocate memory
goroutine 1 [running]:
github.com/wasilibs/wazero-helpers/allocator.alloc(0x1911020?, 0x100000000)
/Users/zrice/Go/pkg/mod/github.com/wasilibs/wazero-helpers@v0.0.0-20240620070341-3dff1577cd52/allocator/nonmoving_unix.go:33 +0x10e
github.com/tetratelabs/wazero/experimental.MemoryAllocatorFunc.Allocate(0xa84539?, 0xd4ac60?, 0x47d43a?)
/Users/zrice/Go/pkg/mod/github.com/tetratelabs/wazero@v1.9.0/experimental/memory.go:28 +0x1c
github.com/tetratelabs/wazero/internal/wasm.NewMemoryInstance(0xc000013d70, {0x7fd5732baa00?, 0xe87630?}, {0xf90c48, 0xc000035680})
/Users/zrice/Go/pkg/mod/github.com/tetratelabs/wazero@v1.9.0/internal/wasm/memory.go:78 +0xab
github.com/tetratelabs/wazero/internal/wasm.(*ModuleInstance).buildMemory(0xc0000f8f00, 0xc0001e71e0, {0x7fd5732baa00?, 0xe87630?})
/Users/zrice/Go/pkg/mod/github.com/tetratelabs/wazero@v1.9.0/internal/wasm/module.go:653 +0x4c
github.com/tetratelabs/wazero/internal/wasm.(*Store).instantiate(0xc0000902a0, {0xf8a300, 0xc000222a80}, 0xc0001e71e0, {0xe18d1d, 0x3}, 0xc0000c2420, {0x1932260, 0x0, 0x0})
/Users/zrice/Go/pkg/mod/github.com/tetratelabs/wazero@v1.9.0/internal/wasm/store.go:370 +0x348
github.com/tetratelabs/wazero/internal/wasm.(*Store).Instantiate(0xc0000902a0, {0xf8a300, 0xc000222a80}, 0x0?, {0xe18d1d?, 0x0?}, 0x0?, {0x1932260, 0x0, 0x0})
/Users/zrice/Go/pkg/mod/github.com/tetratelabs/wazero@v1.9.0/internal/wasm/store.go:327 +0x5a
github.com/tetratelabs/wazero.(*runtime).InstantiateModule(0xc0002238c0, {0xf8a300, 0xc000222a80}, {0xf8e7e0, 0xc000256740}, {0xf92da0, 0xc00026e1e0})
/Users/zrice/Go/pkg/mod/github.com/tetratelabs/wazero@v1.9.0/runtime.go:337 +0x1e5
github.com/tetratelabs/wazero.(*runtime).InstantiateWithConfig(0xc0002238c0, {0xf8a300, 0xc000222a80}, {0x1528cd0?, 0xd45020?, 0xe87630?}, {0xf92da0, 0xc00026e1e0})
/Users/zrice/Go/pkg/mod/github.com/tetratelabs/wazero@v1.9.0/runtime.go:302 +0x74
github.com/wasilibs/go-re2/internal.init.0()
/Users/zrice/Go/pkg/mod/github.com/wasilibs/go-re2@v1.9.0/internal/re2_wazero.go:184 +0x39c
```
The problem is that wazero's allocator reserves 4GB of virtual address space upfront (not physical memory) using mmap with PROT_NONE. This reservation happens at module initialization before any actual memory is committed. In environments with rlimit_as constraints (address space limit), this 4GB reservation fails because it exceeds the available virtual address space, even though it wouldn't consume actual RAM.
Contributor guide
Assessment
This issue has not been assessed yet.