Skip to content

runtime.setMemoryLimit doesn’t prevent host OOM with prebuilt wasm (memory growth enabled) #255

@fedorkar

Description

@fedorkar

Repro

import ReleaseSync from "@jitl/quickjs-wasmfile-release-sync";
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core";

const QuickJS = await newQuickJSWASMModuleFromVariant(ReleaseSync);
const rt = QuickJS.newRuntime();
rt.setMemoryLimit(64 * 1024 * 1024);

const ctx = rt.newContext();
ctx.evalCode(`
  const chunks = [];
  while (true) { chunks.push("x".repeat(1024 * 1024)); }
`);

Expected

QuickJS throws an OOM error when the limit is exceeded.

Actual

Process memory keeps growing and the host eventually OOMs / runtime crashes. No QuickJS OOM is raised.

Note / workaround

If I build a custom wasm with:

  • MPORTED_MEMORY=1
  • ALLOW_MEMORY_GROWTH=0
  • fixed INITIAL_MEMORY/MAXIMUM_MEMORY
    and pass a fixed WebAssembly.Memory via newVariant, the same script consistently throws a QuickJS OOM instead of crashing.

Question

Is there a prebuilt “fixed memory” variant intended for sandbox use, or a recommended way to enforce hard memory caps with the prebuilt wasm?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions