Skip to content

Commit

Permalink
limit store contents
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jun 25, 2024
1 parent 8bcbf8c commit 12b56a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtime/stdlib/webassembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func newWebAssemblyCompileAndInstantiateFunction(
panic(err)

Check warning on line 44 in runtime/stdlib/webassembly.go

View check run for this annotation

Codecov / codecov/patch

runtime/stdlib/webassembly.go#L44

Added line #L44 was not covered by tests
}

// TODO meter

module, err := handler.CompileWebAssembly(bytes)
if err != nil {
panic(err)

Check warning on line 51 in runtime/stdlib/webassembly.go

View check run for this annotation

Codecov / codecov/patch

runtime/stdlib/webassembly.go#L51

Added line #L51 was not covered by tests
Expand Down
17 changes: 17 additions & 0 deletions runtime/webassembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,25 @@ func NewWasmtimeWebAssemblyModule(bytes []byte) (stdlib.WebAssemblyModule, error
config.SetCraneliftFlag("enable_nan_canonicalization", "true")

engine := wasmtime.NewEngineWithConfig(config)

store := wasmtime.NewStore(engine)

// TODO: define memory limit
const todoMemoryLimit = 2 * 1024 * 1024
// TODO: define table elements limit
const tableElementsLimit = 10_000
// TODO: define tables limit
const todoTablesLimit = 1
// TODO: define memories limit
const todoMemoriesLimit = 1
store.Limiter(
todoMemoryLimit,
tableElementsLimit,
-1,
todoTablesLimit,
todoMemoriesLimit,
)

module, err := wasmtime.NewModule(engine, bytes)
if err != nil {
// TODO: wrap error
Expand Down

0 comments on commit 12b56a5

Please sign in to comment.