Skip to content

Commit ef567c4

Browse files
authored
Keep snapshot images shallow so serializing and restoring them cannot overflow the stack (#59)
1 parent 359f44d commit ef567c4

5 files changed

Lines changed: 342 additions & 92 deletions

File tree

‎src/jvm.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { intrinsics, natives as builtinNatives } from "./natives/index.ts";
2323
import { invokePolymorphic, linkCallSite, resolveConstant } from "./indy.ts";
2424
import { hostNative, jniNames } from "./hostnatives.ts";
2525
import { Library } from "./library.ts";
26-
import { dumpVM, restoreVM, snapshotKey } from "./snapshot.ts";
26+
import { dumpVM, restoreVM, snapshotKey, SNAPSHOT_FORMAT } from "./snapshot.ts";
2727
import type { SnapshotImage, WarmSnapshotImage } from "./snapshot.ts";
2828
import type { SavedJit } from "./jit.ts";
2929
import type { LibraryRequest } from "./library.ts";
@@ -1262,7 +1262,7 @@ export class JVM {
12621262
const build = snaps.build;
12631263
this.warmKey = JSON.stringify([snapshotKey(this, build), this.opts.classpath ?? [], this.opts.cwd ?? "/", this.props.get("sun.java.command") ?? null]);
12641264
const useWarm = (image: WarmSnapshotImage | null) => {
1265-
if (!image) return false;
1265+
if (image?.format !== SNAPSHOT_FORMAT) return false;
12661266
let mismatch: string | null;
12671267
try {
12681268
mismatch = image.warmKey === this.warmKey && image.key === snapshotKey(this, build) ? this.fs.warmTraceMismatch(image.trace) : "key changed";
@@ -1305,7 +1305,7 @@ export class JVM {
13051305
const key = snapshotKey(this, snaps.build);
13061306
const done = (image: SnapshotImage | null) => {
13071307
// an async load can finish after the VM was halted
1308-
if (image?.key !== key || this.exitCode !== null) return start(false);
1308+
if (image?.format !== SNAPSHOT_FORMAT || image.key !== key || this.exitCode !== null) return start(false);
13091309
try {
13101310
restoreVM(this, image, t);
13111311
} catch (e) {

0 commit comments

Comments
 (0)