Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): stamp crash reports with the crashed version (PRD-7768) (#3163)

Andrew Mikofalvyc1cf713e7180
diff --git a/.changeset/crash-report-crashed-version.md b/.changeset/crash-report-crashed-version.md
new file mode 100644
index 000000000..6948b2144
--- /dev/null
+++ b/.changeset/crash-report-crashed-version.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+A bug report filed after a crash now names the version that actually crashed. The report is composed by the session that notices the crash on the next launch, and if an automatic update landed in between, that is a different build from the one that died. Reports were being attributed to the new build, which in some cases had only been running for a fraction of a second before it was asked to explain a crash it never saw. The crashed version is now read from the crash dump's own metadata, or from the marker the previous session left behind, and it appears in the report alongside the version you are running now. Seeing the two together is the point: when they differ, an update happened between the crash and the report, and the crash belongs to the older build. When a report cannot establish which version crashed, it says nothing rather than guessing, so a stated version can always be trusted.
diff --git a/packages/app/src/components/ReportBugDialog.dom.test.tsx b/packages/app/src/components/ReportBugDialog.dom.test.tsx
index 0aeefeb82..207b1fcf1 100644
--- a/packages/app/src/components/ReportBugDialog.dom.test.tsx
+++ b/packages/app/src/components/ReportBugDialog.dom.test.tsx
@@ -655,6 +655,36 @@ describe('ReportBugDialog', () => {
expect(log.createCalls[0]).not.toHaveProperty('includeCrashDump');
});
+ test('a crash invite that names the crashed version folds it in last', async () => {
+ // Last, not first: with an empty note these context lines ARE the note,
+ // and the intake takes the ticket title from the note's first line.
+ const log = installBridge();
+ await renderDialog({ crashInvite: { ...BOOT_INVITE, crashedAppVersion: '0.41.0' } });
+
+ await userEvent.click(screen.getByRole('button', { name: 'Create report' }));
+ await screen.findByRole('heading', { name: 'Review your report' });
+
+ expect(log.createCalls).toEqual([
+ {
+ level: 'full',
+ note: 'Crash source: previous session ended without a clean quit\nCrash event: boot:1751871600000\nCrashed app version: 0.41.0',
+ includeCrashDump: true,
+ },
+ ]);
+ });
+
+ test('a crash invite with no crashed version composes the note without that line', async () => {
+ // An older build's dump, or a sentinel that predates the field, must not
+ // leave a dangling label a triager would read as a real value.
+ const log = installBridge();
+ await renderDialog({ crashInvite: BOOT_INVITE });
+
+ await userEvent.click(screen.getByRole('button', { name: 'Create report' }));
+ await screen.findByRole('heading', { name: 'Review your report' });
+
+ expect(log.createCalls[0]?.note).not.toContain('Crashed app version');
+ });
+
test('the plain compose never renders the crash-dump opt-in and never sends the flag', async () => {
const log = installBridge();
await renderDialog();
diff --git a/packages/app/src/components/ReportBugDialogBody.tsx b/packages/app/src/components/ReportBugDialogBody.tsx
index 05ccb031b..08fe6ba21 100644
--- a/packages/app/src/components/ReportBugDialogBody.tsx
+++ b/packages/app/src/components/ReportBugDialogBody.tsx
@@ -170,7 +170,19 @@ function crashInviteLines(invite: OkBugReportCrashDetectedEvent): string[] {
: 'new crash dump found from the previous session';
// The event id keys the crash to main's local acknowledgment/minidump state
// during triage (it encodes the crashed session or dump timestamp).
- return [`Crash source: ${source}`, `Crash event: ${invite.eventId}`];
+ const lines = [`Crash source: ${source}`, `Crash event: ${invite.eventId}`];
+ // Appended, never prepended: with an empty note the context lines ARE the
+ // note, and the intake takes its ticket title from the note's first line.
+ //
+ // Stated even when it matches the version the report itself is stamped with.
+ // The pair is the diagnostic: two versions side by side say an update landed
+ // between the crash and the report, and one repeated says it did not — a
+ // line that appeared only on disagreement would leave a reader unable to
+ // tell agreement from a build too old to answer.
+ if (invite.kind === 'boot' && invite.crashedAppVersion !== undefined) {
+ lines.push(`Crashed app version: ${invite.crashedAppVersion}`);
+ }
+ return lines;
}
type Phase =
diff --git a/packages/core/src/logger-types.ts b/packages/core/src/logger-types.ts
index 191de4958..7b2a01470 100644
--- a/packages/core/src/logger-types.ts
+++ b/packages/core/src/logger-types.ts
@@ -198,6 +198,18 @@ export type OkBugReportCrashDetectedEvent =
kind: 'boot';
context: { dirtyShutdown: boolean; newMinidumps: number };
minidumpAvailable: boolean;
+ /**
+ * App version of the session that CRASHED, which is not the version now
+ * running whenever an auto-update landed between the crash and this
+ * launch. Absent when neither the crashed session's sentinel nor the
+ * minidump's own annotations name one — an unknown version is reported
+ * as unknown rather than approximated by the running one.
+ *
+ * Only the boot variant carries it. The two runtime variants are raised
+ * by the very session that crashed, so their crashed version is the
+ * running version by construction and a field would be pure restatement.
+ */
+ crashedAppVersion?: string;
};
/**
diff --git a/packages/desktop/src/main/crash-detection.test.ts b/packages/desktop/src/main/crash-detection.test.ts
index f3c14ca71..210a30512 100644
--- a/packages/desktop/src/main/crash-detection.test.ts
+++ b/packages/desktop/src/main/crash-detection.test.ts
@@ -48,15 +48,27 @@ const FOREIGN_DUMP = buildMinidump([
/** Truncated past the header — the shape a crash-during-dump-write leaves. */
const UNPARSEABLE_DUMP = Buffer.from('minidump-bytes-that-are-not-a-minidump');
+/**
+ * The version a rig runs as by default, and the one it is updated to when a
+ * test needs the crashed session and the detecting session to disagree — which
+ * is the whole point of recording the crashed one separately.
+ */
+const CRASHED_VERSION = '0.41.0';
+const DETECTING_VERSION = '0.46.1';
+
interface Rig {
deps: CrashDetectionDeps;
emitted: OkBugReportCrashDetectedEvent[];
/** A dump naming one of this rig's own executables as its main module. */
ownDump: Buffer;
+ /** The same dump, plus the Crashpad annotations a real one carries. */
+ ownDumpStamped(version: string): Buffer;
/** Flip to false to simulate "no live renderer window can take the event". */
setRendererAvailable(available: boolean): void;
/** Swap the kernel boot-session identity, simulating a reboot between sessions. */
setBootSessionUuid(uuid: string | null): void;
+ /** Swap the running app version, simulating an auto-update between sessions. */
+ setAppVersion(version: string): void;
/** Advance and return the fake clock (10s per tick). */
tick(): Date;
dir: string;
@@ -70,29 +82,37 @@ function makeRig(): Rig {
let bootSessionUuid: string | null = 'boot-epoch-a';
let clockMs = Date.parse('2026-07-10T00:00:00.000Z');
const appBundleRoot = join(dir, 'Applications', 'OpenKnowledge.app');
- return {
+ // A helper process rather than the main binary: renderer/GPU/utility crashes
+ // are the common case, and they must resolve inside the bundle root too.
+ const ownModules = [
+ join(
+ appBundleRoot,
+ 'Contents',
+ 'Frameworks',
+ 'OpenKnowledge Helper (Renderer).app',
+ 'Contents',
+ 'MacOS',
+ 'OpenKnowledge Helper (Renderer)',
+ ),
+ '/usr/lib/dyld',
+ ];
+ const rig: Rig = {
dir,
emitted,
- // A helper process rather than the main binary: renderer/GPU/utility crashes
- // are the common case, and they must resolve inside the bundle root too.
- ownDump: buildMinidump([
- join(
- appBundleRoot,
- 'Contents',
- 'Frameworks',
- 'OpenKnowledge Helper (Renderer).app',
- 'Contents',
- 'MacOS',
- 'OpenKnowledge Helper (Renderer)',
- ),
- '/usr/lib/dyld',
- ]),
+ ownDump: buildMinidump(ownModules),
+ ownDumpStamped: (version: string) =>
+ buildMinidump(ownModules, {
+ annotations: { _productName: 'OpenKnowledge', _version: version, prod: 'Electron' },
+ }),
setRendererAvailable(available: boolean) {
rendererAvailable = available;
},
setBootSessionUuid(uuid: string | null) {
bootSessionUuid = uuid;
},
+ setAppVersion(version: string) {
+ rig.deps.appVersion = version;
+ },
tick() {
clockMs += 10_000;
return new Date(clockMs);
@@ -102,6 +122,7 @@ function makeRig(): Rig {
ackStorePath: join(dir, 'user-data', 'bug-report-crash-acks.json'),
crashDumpsDir: join(dir, 'crash-dumps'),
appBundleRoot,
+ appVersion: CRASHED_VERSION,
emit(event) {
if (!rendererAvailable) return false;
emitted.push(event);
@@ -115,6 +136,19 @@ function makeRig(): Rig {
logger: silentLogger,
},
};
+ return rig;
+}
+
+/**
+ * Narrow an armed invitation to the boot variant, failing if there isn't one.
+ * Throwing rather than returning null keeps a regression in arming from
+ * quietly reducing a caller to zero assertions, which an `if (kind === 'boot')`
+ * guard around the interesting expectations would do.
+ */
+function bootInvite(armed: OkBugReportCrashDetectedEvent | null) {
+ expect(armed?.kind).toBe('boot');
+ if (armed?.kind !== 'boot') throw new Error('expected a boot invitation, got none');
+ return armed;
}
function readSentinel(rig: Rig): Record<string, string | undefined> {
@@ -866,3 +900,298 @@ describe('process-level invariants', () => {
expect(calls).toEqual([{ uploadToServer: false }]);
});
});
+
+/**
+ * Which version a boot-time invitation names. The report is composed by the
+ * session that DETECTS the crash, which an auto-update in between makes a
+ * different build from the one that died — and the detecting session's own
+ * version is the one thing that must never be substituted, since it is exactly
+ * the wrong answer in the case worth reporting.
+ */
+describe('the version a boot invitation attributes the crash to', () => {
+ test('a dirty shutdown names the crashed version, not the detecting one', () => {
+ const rig = makeRig();
+ createCrashDetection(rig.deps).detectBootCrash();
+
+ // The app is replaced by an auto-update before the next launch notices.
+ rig.setAppVersion(DETECTING_VERSION);
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.context.dirtyShutdown).toBe(true);
+ expect(armed.crashedAppVersion).toBe(CRASHED_VERSION);
+ });
+
+ test('a dirty shutdown keeps its sentinel as witness even with a dump of its own', () => {
+ // The ordinary same-boot-session crash, and the pivot the whole attribution
+ // turns on: both witnesses are present and they disagree, and the sentinel
+ // is the one that decided the event id, so it is the one that names the
+ // version. A refactor that made a sentinel-present shutdown dump-driven
+ // would read the dump here instead — silently, with every neighbouring
+ // test still green, since each of those has only one witness to choose from.
+ const rig = makeRig();
+ createCrashDetection(rig.deps).detectBootCrash();
+ const bootId = readSentinel(rig).bootId;
+ seedMinidump(rig, 'pending/native.dmp', rig.tick(), rig.ownDumpStamped('0.41.0-beta.4'));
+
+ rig.setAppVersion(DETECTING_VERSION);
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.context.dirtyShutdown).toBe(true);
+ // Asserted as the exact id rather than "not a dump id": the form names
+ // which witness decided, which is the thing the version has to follow.
+ expect(armed.eventId).toBe(`boot:${bootId}`);
+ expect(armed.crashedAppVersion).toBe(CRASHED_VERSION);
+ });
+
+ test('a dump-driven event reads the version stamped inside the dump', () => {
+ // No sentinel survives a clean quit, so the dump is the only witness left.
+ const rig = makeRig();
+ const sessionA = createCrashDetection(rig.deps);
+ sessionA.detectBootCrash();
+ sessionA.markCleanQuit();
+ seedMinidump(rig, 'pending/native.dmp', rig.tick(), rig.ownDumpStamped(CRASHED_VERSION));
+
+ rig.setAppVersion(DETECTING_VERSION);
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.eventId).toStartWith('boot:dump:');
+ expect(armed.context.dirtyShutdown).toBe(false);
+ expect(armed.crashedAppVersion).toBe(CRASHED_VERSION);
+ });
+
+ test('the dump wins over the sentinel when a reboot makes the event dump-driven', () => {
+ // Both witnesses exist here and they disagree. The dump is the more
+ // precise one: it was written at the moment of the crash, while the
+ // sentinel only records the session that happened to be running.
+ const rig = makeRig();
+ createCrashDetection(rig.deps).detectBootCrash();
+ seedMinidump(rig, 'pending/native.dmp', rig.tick(), rig.ownDumpStamped('0.41.0-beta.3'));
+
+ rig.setBootSessionUuid('boot-epoch-b');
+ rig.setAppVersion(DETECTING_VERSION);
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.eventId).toStartWith('boot:dump:');
+ expect(armed.crashedAppVersion).toBe('0.41.0-beta.3');
+ });
+
+ test('the version comes from the dump the event names, not the newest one', () => {
+ // A descendant process that inherited our exception handler crashes AFTER
+ // we do, and Crashpad stamps OUR annotations onto its dump — so the newest
+ // dump in the database names the post-update build while describing an
+ // unrelated program's death. Taking it would reinstate exactly the
+ // misattribution this attributes around, and it sorts first.
+ const rig = makeRig();
+ const sessionA = createCrashDetection(rig.deps);
+ sessionA.detectBootCrash();
+ sessionA.markCleanQuit();
+ const ourCrashAt = rig.tick();
+ seedMinidump(rig, 'pending/ours.dmp', ourCrashAt, rig.ownDumpStamped(CRASHED_VERSION));
+ seedMinidump(
+ rig,
+ 'pending/descendant.dmp',
+ rig.tick(),
+ buildMinidump(['/Applications/LibreOffice.app/Contents/MacOS/soffice'], {
+ annotations: { _version: DETECTING_VERSION },
+ }),
+ );
+
+ rig.setAppVersion(DETECTING_VERSION);
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ // The id is keyed to our dump, and the version has to describe that same one.
+ expect(armed.eventId).toBe(`boot:dump:${ourCrashAt.getTime()}`);
+ expect(armed.crashedAppVersion).toBe(CRASHED_VERSION);
+ });
+
+ test('an unreadable dump ahead of an owned one leaves the version unknown', () => {
+ // Arming fails open on a dump it cannot parse, so that dump still counts
+ // toward the event and, being newest, still names it — and then the version
+ // has to describe that same dump, which has nothing to say. Reading the
+ // owned dump behind it would pin a version to an event id that names a
+ // different crash. The silence is the intended outcome, not a gap: unknown
+ // stays unknown, and the version never describes a dump other than the one
+ // the reader is looking at.
+ const rig = makeRig();
+ const sessionA = createCrashDetection(rig.deps);
+ sessionA.detectBootCrash();
+ sessionA.markCleanQuit();
+ seedMinidump(rig, 'pending/ours.dmp', rig.tick(), rig.ownDumpStamped(CRASHED_VERSION));
+ const tornAt = rig.tick();
+ seedMinidump(rig, 'pending/torn.dmp', tornAt, UNPARSEABLE_DUMP);
+
+ rig.setAppVersion(DETECTING_VERSION);
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.eventId).toBe(`boot:dump:${tornAt.getTime()}`);
+ expect(armed.crashedAppVersion).toBeUndefined();
+ // Only the version was declined. The owned dump behind it is still there
+ // to attach, so the silence costs the report nothing else.
+ expect(armed.minidumpAvailable).toBe(true);
+ });
+
+ test('an unchanged version is still reported, so agreement is legible', () => {
+ // Silence would be ambiguous: a reader could not tell "the same build" from
+ // "too old to say".
+ const rig = makeRig();
+ createCrashDetection(rig.deps).detectBootCrash();
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.crashedAppVersion).toBe(CRASHED_VERSION);
+ expect(rig.deps.appVersion).toBe(CRASHED_VERSION);
+ });
+
+ test('a sentinel written before the field existed still prompts, with no version', () => {
+ // The sentinel is read across app-version boundaries, so an older binary's
+ // file must degrade to unknown rather than break detection.
+ const rig = makeRig();
+ mkdirSync(dirname(rig.deps.sentinelPath), { recursive: true });
+ writeFileSync(
+ rig.deps.sentinelPath,
+ `${JSON.stringify({ bootId: '1784494925550', startedAt: '2026-07-09T21:02:05.550Z' })}\n`,
+ );
+
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.eventId).toBe('boot:1784494925550');
+ expect(armed.crashedAppVersion).toBeUndefined();
+ });
+
+ test('a sentinel version that could forge a report line is refused', () => {
+ // The sentinel is a file on disk like any other, and its value lands on
+ // the same line-oriented report body the dump annotation does, so it gets
+ // the same gate rather than being trusted for having been ours once.
+ const rig = makeRig();
+ mkdirSync(dirname(rig.deps.sentinelPath), { recursive: true });
+ writeFileSync(
+ rig.deps.sentinelPath,
+ `${JSON.stringify({
+ bootId: '1784494925550',
+ startedAt: '2026-07-09T21:02:05.550Z',
+ appVersion: `0.41.0${String.fromCharCode(10)}Crash source: something untrue`,
+ })}\n`,
+ );
+
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.crashedAppVersion).toBeUndefined();
+ });
+
+ test('a dump carrying no annotations still arms and attaches, with no version', () => {
+ // Absence of a version must never cost the report anything else.
+ const rig = makeRig();
+ const sessionA = createCrashDetection(rig.deps);
+ sessionA.detectBootCrash();
+ sessionA.markCleanQuit();
+ seedMinidump(rig, 'pending/native.dmp', rig.tick());
+
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.minidumpAvailable).toBe(true);
+ expect(armed.crashedAppVersion).toBeUndefined();
+ });
+
+ test('a dump whose annotations are unreadable still arms, with no version', () => {
+ const rig = makeRig();
+ const sessionA = createCrashDetection(rig.deps);
+ sessionA.detectBootCrash();
+ sessionA.markCleanQuit();
+ const corrupt = buildMinidump(
+ [
+ join(
+ rig.deps.appBundleRoot,
+ 'Contents',
+ 'Frameworks',
+ 'OpenKnowledge Helper (Renderer).app',
+ 'Contents',
+ 'MacOS',
+ 'OpenKnowledge Helper (Renderer)',
+ ),
+ ],
+ { annotations: { _version: CRASHED_VERSION }, annotationsRva: 0xffff },
+ );
+ seedMinidump(rig, 'pending/native.dmp', rig.tick(), corrupt);
+
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.minidumpAvailable).toBe(true);
+ expect(armed.crashedAppVersion).toBeUndefined();
+ });
+
+ test("this session's sentinel records the version now running", () => {
+ const rig = makeRig();
+ rig.setAppVersion(DETECTING_VERSION);
+ createCrashDetection(rig.deps).detectBootCrash();
+
+ expect(readSentinel(rig).appVersion).toBe(DETECTING_VERSION);
+ });
+
+ test('the boot breadcrumb carries both versions', () => {
+ // This log line is what an incident gets reconstructed from when no report
+ // was ever filed, so the pair has to be legible there too.
+ const rig = makeRig();
+ createCrashDetection(rig.deps).detectBootCrash();
+
+ const infoLines: Array<Record<string, unknown>> = [];
+ rig.deps.logger = {
+ info: (payload: Record<string, unknown>) => {
+ infoLines.push(payload);
+ },
+ warn: () => {},
+ };
+ rig.setAppVersion(DETECTING_VERSION);
+ createCrashDetection(rig.deps).detectBootCrash();
+
+ const breadcrumb = infoLines.find((line) => line.event === 'crash-detection.boot');
+ expect(breadcrumb?.crashedAppVersion).toBe(CRASHED_VERSION);
+ expect(breadcrumb?.detectingAppVersion).toBe(DETECTING_VERSION);
+ });
+
+ test('the boot breadcrumb tells an absent version apart from a broken parse', () => {
+ // A dump too old to carry the annotation and a parser that broke on a
+ // Crashpad layout change both reach the report as no version at all, and
+ // they send whoever debugs it in opposite directions. The flag beside the
+ // version is the only thing that separates them, so a dump that simply
+ // registered no annotations is the case that must NOT read as a failure.
+ const rig = makeRig();
+ const sessionA = createCrashDetection(rig.deps);
+ sessionA.detectBootCrash();
+ sessionA.markCleanQuit();
+ seedMinidump(rig, 'pending/native.dmp', rig.tick());
+
+ const infoLines: Array<Record<string, unknown>> = [];
+ rig.deps.logger = {
+ info: (payload: Record<string, unknown>) => {
+ infoLines.push(payload);
+ },
+ warn: () => {},
+ };
+ createCrashDetection(rig.deps).detectBootCrash();
+
+ const breadcrumb = infoLines.find((line) => line.event === 'crash-detection.boot');
+ expect(breadcrumb?.crashedAppVersion).toBeNull();
+ expect(breadcrumb?.crashedAppVersionParseFailed).toBe(false);
+ });
+
+ test('a foreign dump does not make the event dump-driven', () => {
+ // A descendant process crashing is not this app crashing, so its dump must
+ // not flip the event off the sentinel path — and the sentinel, not the
+ // version the foreign dump happens to carry, stays the witness.
+ const rig = makeRig();
+ createCrashDetection(rig.deps).detectBootCrash();
+ seedMinidump(
+ rig,
+ 'pending/foreign.dmp',
+ rig.tick(),
+ buildMinidump(['/Applications/LibreOffice.app/Contents/MacOS/soffice'], {
+ annotations: { _version: '9.9.9' },
+ }),
+ );
+
+ rig.setAppVersion(DETECTING_VERSION);
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.context.dirtyShutdown).toBe(true);
+ expect(armed.crashedAppVersion).toBe(CRASHED_VERSION);
+ });
+});
diff --git a/packages/desktop/src/main/crash-detection.ts b/packages/desktop/src/main/crash-detection.ts
index ccd259bd2..c8b3577f6 100644
--- a/packages/desktop/src/main/crash-detection.ts
+++ b/packages/desktop/src/main/crash-detection.ts
@@ -55,7 +55,12 @@ import {
} from 'node:fs';
import { dirname, join } from 'node:path';
import type { OkBugReportCrashDetectedEvent } from '@inkeep/open-knowledge-core';
-import { classifyMinidumpOwnership, type MinidumpOwnership } from './minidump-ownership.ts';
+import { asReportableAppVersion } from './crashed-app-version.ts';
+import {
+ classifyMinidumpOwnership,
+ type MinidumpOwnership,
+ readMinidumpAppVersion,
+} from './minidump-ownership.ts';
/**
* Process-gone reasons that read as genuine crashes. `clean-exit` and
@@ -102,12 +107,14 @@ interface CrashAckStore {
}
/**
- * On-disk sentinel contents for the running session. No version field —
+ * On-disk sentinel contents for the running session. No FORMAT version field —
* forward/backward compatibility instead relies on every field staying
* add-only (never renamed or repurposed) and `field()` in `detectBootCrash`
* returning null for any key a reader doesn't recognize, since this file is
* read across app-version boundaries (auto-update can start a new binary
- * against a sentinel an older one wrote).
+ * against a sentinel an older one wrote). `appVersion` below names the app,
+ * not this file's shape — it is content, covered by that contract like any
+ * other field rather than being an exception to it.
*/
interface SentinelState {
bootId: string;
@@ -120,6 +127,13 @@ interface SentinelState {
pendingOsShutdownAt?: string;
/** Set on suspend, cleared on resume — a never-resumed sentinel died asleep. */
suspendedAt?: string;
+ /**
+ * App version of the session that wrote this sentinel. Read back by the NEXT
+ * session to name the build that actually crashed: an auto-update between
+ * the two is precisely when it differs from the running one. Absent on a
+ * sentinel written before this field existed, which reads as unknown.
+ */
+ appVersion?: string;
}
export interface CrashDetectionDeps {
@@ -137,6 +151,12 @@ export interface CrashDetectionDeps {
* database also collects dumps for programs we merely spawned.
*/
appBundleRoot: string;
+ /**
+ * Version of the RUNNING session, recorded into this boot's sentinel so the
+ * next boot can name it if this one dies. Never used to describe a crash
+ * detected during this boot — that crash belongs to an earlier session.
+ */
+ appVersion: string;
/**
* Push one crash-detected event to a live renderer. Returns false when no
* renderer could take it — the event stays armed and is re-offered on the
@@ -453,6 +473,7 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
let prevLastAliveAt: string | null = null;
let prevPendingOsShutdownAt: string | null = null;
let prevSuspendedAt: string | null = null;
+ let prevAppVersion: string | null = null;
if (sentinelRaw !== null) {
try {
const parsed = JSON.parse(sentinelRaw) as Record<string, unknown> | null;
@@ -465,6 +486,13 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
prevLastAliveAt = field('lastAliveAt');
prevPendingOsShutdownAt = field('pendingOsShutdownAt');
prevSuspendedAt = field('suspendedAt');
+ // Must be read here, before this boot overwrites the file below:
+ // afterwards the value on disk is the RUNNING version, which is the
+ // wrong answer in exactly the update-between-sessions case that
+ // makes the question worth asking. Gated like the minidump's
+ // annotation because it reaches the same line of the same report,
+ // and this file is no more trustworthy than that one.
+ prevAppVersion = asReportableAppVersion(field('appVersion'));
} catch {
// Torn write from the crashed session — presence alone is the signal.
}
@@ -580,6 +608,33 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
? `boot:dump:${Math.max(...newDumps)}`
: `boot:${prevBootId ?? `unreadable:${detectedAt.getTime()}`}`;
if (!store.ackedEventIds.includes(eventId)) {
+ // The version of the session that DIED, which an auto-update between
+ // the crash and this launch makes different from the running one.
+ //
+ // Both witnesses can be present at once — a reboot that killed a
+ // session with a fresh dump leaves a sentinel AND a dump — so this
+ // is a priority rule, not a partition of disjoint cases. The dump
+ // wins wherever it decides the event: it was stamped at the instant
+ // the process died, while the sentinel only names whichever session
+ // happened to be running.
+ //
+ // Skipping foreign dumps is load-bearing rather than tidiness.
+ // Crashpad stamps OUR annotations onto dumps it writes for
+ // descendant processes, so a foreign one carries the CURRENT version
+ // while describing an unrelated program's death — and, being newer,
+ // would sort ahead of ours. Skipping it is what makes the first
+ // entry of this newest-first list the same dump `newDumps` took the
+ // event id's maximum from.
+ //
+ // Unknown stays unknown. Falling back to the running version here
+ // would reproduce the misattribution this exists to remove, in a
+ // form no reader could detect.
+ const eventDump = dumpDriven
+ ? freshDumps.find((d) => d.ownership !== 'foreign')
+ : undefined;
+ const dumpVersion =
+ eventDump === undefined ? null : readMinidumpAppVersion(eventDump.entry.path);
+ const crashedAppVersion = dumpDriven ? (dumpVersion?.version ?? null) : prevAppVersion;
const event: OkBugReportCrashDetectedEvent = {
eventId,
kind: 'boot',
@@ -589,6 +644,7 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
// counts only dumps we proved are ours, never the fail-open set
// that decided whether to prompt at all.
minidumpAvailable: ownedDumpCount > 0,
+ ...(crashedAppVersion !== null ? { crashedAppVersion } : {}),
};
if (armInvite(event)) {
armed = event;
@@ -599,6 +655,16 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
detectedAt: detectedAt.toISOString(),
dirtyShutdown: !dumpDriven,
newMinidumps: newDumps.length,
+ // Logged even when null: this line is what an incident gets
+ // reconstructed from, and "we could not tell" is itself the
+ // finding when the two sources both come up empty.
+ crashedAppVersion,
+ // Which kind of silence that was. A dump predating the
+ // annotation and a parser that broke on a Crashpad layout
+ // change both reach the report as no version at all, and they
+ // send whoever debugs it in opposite directions.
+ crashedAppVersionParseFailed: dumpVersion?.parseFailed ?? false,
+ detectingAppVersion: deps.appVersion,
},
'previous session ended uncleanly — arming report invitation',
);
@@ -615,6 +681,7 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
bootId: String(detectedAt.getTime()),
startedAt: detectedAt.toISOString(),
lastAliveAt: detectedAt.toISOString(),
+ appVersion: deps.appVersion,
...(bootSessionUuid !== null ? { bootSessionUuid } : {}),
};
writeSentinel('arm');
diff --git a/packages/desktop/src/main/crashed-app-version.test.ts b/packages/desktop/src/main/crashed-app-version.test.ts
new file mode 100644
index 000000000..52c6ec872
--- /dev/null
+++ b/packages/desktop/src/main/crashed-app-version.test.ts
@@ -0,0 +1,78 @@
+/**
+ * The gate every crashed-session version passes before it reaches a log line
+ * or a bug report body.
+ *
+ * Both witnesses that answer "which build died" are files this process did not
+ * write during the run that reads them, so the value is untrusted input on a
+ * line-oriented destination. The property is one-directional: nothing that
+ * could forge or distort a line may pass, and a rejection costs only the
+ * version, which the report already knows how to say nothing about.
+ */
+
+import { describe, expect, test } from 'vitest';
+import { asReportableAppVersion } from './crashed-app-version.ts';
+
+describe('versions that describe a real build', () => {
+ test('a release version passes through unchanged', () => {
+ expect(asReportableAppVersion('0.41.0')).toBe('0.41.0');
+ });
+
+ test('a prerelease with build metadata passes through unchanged', () => {
+ // The widest shape semver allows, so the gate is not quietly stricter than
+ // the versions this app actually cuts.
+ expect(asReportableAppVersion('0.47.0-beta.3+build.2026')).toBe('0.47.0-beta.3+build.2026');
+ });
+
+ test('the full printable-ASCII range is admitted', () => {
+ const printable = Array.from({ length: 0x7f - 0x20 }, (_, i) =>
+ String.fromCharCode(0x20 + i),
+ ).join('');
+ expect(asReportableAppVersion(printable)).toBe(printable);
+ });
+});
+
+describe('values that cannot be vouched for', () => {
+ test('an absent version stays absent', () => {
+ expect(asReportableAppVersion(null)).toBeNull();
+ expect(asReportableAppVersion(undefined)).toBeNull();
+ expect(asReportableAppVersion('')).toBeNull();
+ });
+
+ /**
+ * Every rejected case is a character that would let the value forge or
+ * distort the line it lands on. A reject-list would have to name all of
+ * them; the whitelist gets each one without knowing it exists, which is the
+ * reason it is written that way.
+ */
+ const LINE_AFFECTING: Array<{ name: string; codePoint: number }> = [
+ { name: 'a line feed', codePoint: 0x0a },
+ { name: 'a carriage return', codePoint: 0x0d },
+ { name: 'a NUL', codePoint: 0x00 },
+ { name: 'an escape (terminal control sequences)', codePoint: 0x1b },
+ { name: 'a DEL', codePoint: 0x7f },
+ { name: 'a C1 control', codePoint: 0x9b },
+ { name: 'a next-line (U+0085)', codePoint: 0x85 },
+ { name: 'a line separator (U+2028)', codePoint: 0x2028 },
+ { name: 'a paragraph separator (U+2029)', codePoint: 0x2029 },
+ { name: 'a right-to-left override (U+202E)', codePoint: 0x202e },
+ { name: 'a right-to-left isolate (U+2067)', codePoint: 0x2067 },
+ ];
+
+ for (const { name, codePoint } of LINE_AFFECTING) {
+ test(`${name} in the middle of an otherwise plausible version is refused`, () => {
+ expect(asReportableAppVersion(`0.41${String.fromCodePoint(codePoint)}.0`)).toBeNull();
+ });
+ }
+
+ test('a version long enough to crowd out the report is refused', () => {
+ expect(asReportableAppVersion('9'.repeat(256))).toBe('9'.repeat(256));
+ expect(asReportableAppVersion('9'.repeat(257))).toBeNull();
+ });
+
+ test('a non-string survives the type boundary without becoming one', () => {
+ // The sentinel is parsed JSON, so any shape can arrive here at runtime no
+ // matter what the declared type says.
+ expect(asReportableAppVersion(41 as unknown as string)).toBeNull();
+ expect(asReportableAppVersion({ toString: () => '0.41.0' } as unknown as string)).toBeNull();
+ });
+});
diff --git a/packages/desktop/src/main/crashed-app-version.ts b/packages/desktop/src/main/crashed-app-version.ts
new file mode 100644
index 000000000..1957a30ea
--- /dev/null
+++ b/packages/desktop/src/main/crashed-app-version.ts
@@ -0,0 +1,40 @@
+/**
+ * The single gate a crashed session's app version passes through before it
+ * reaches a log line or the body of a bug report.
+ *
+ * Two witnesses answer "which build died" — the Crashpad annotation inside a
+ * minidump, and the `appVersion` the previous session left in its sentinel —
+ * and neither is a file this process wrote during this run. Both destinations
+ * are line-oriented, so a value carrying a line break could forge the context
+ * printed around it, and one with no ceiling could push the rest of a report
+ * out of view. One function rather than a check per witness, so the two cannot
+ * come to disagree about what a version is allowed to be.
+ *
+ * Stated as a whitelist rather than a list of characters to reject: the
+ * versions we produce are `app.getVersion()`, printable ASCII by construction,
+ * so anything outside that is not a version this app can vouch for. A reject
+ * list can be under-enumerated — U+0085, U+2028/U+2029, the C1 block and the
+ * bidi overrides all affect how a line renders and none of them is a C0
+ * control — while "what may pass" cannot.
+ */
+
+/** Ample for a semver string with build metadata; a real one is tens of bytes. */
+const MAX_VERSION_LENGTH = 256;
+
+const FIRST_PRINTABLE_ASCII = 0x20;
+const LAST_PRINTABLE_ASCII = 0x7e;
+
+/**
+ * `value` when it is safe to print as a version, otherwise null. Null means
+ * "unknown", and callers must let it stay unknown: substituting the running
+ * version answers a different question than the one asked, and is
+ * indistinguishable from a true answer at the point it is read.
+ */
+export function asReportableAppVersion(value: string | null | undefined): string | null {
+ if (typeof value !== 'string' || value === '' || value.length > MAX_VERSION_LENGTH) return null;
+ for (let i = 0; i < value.length; i += 1) {
+ const code = value.charCodeAt(i);
+ if (code < FIRST_PRINTABLE_ASCII || code > LAST_PRINTABLE_ASCII) return null;
+ }
+ return value;
+}
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index 6fe264aa1..a436e244b 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -6114,6 +6114,9 @@ function bootPrimaryInstance(): void {
// checks each dump's own main module against this root before treating it
// as ours.
appBundleRoot: appBundleRootFromExecutable(app.getPath('exe')),
+ // Recorded into this boot's sentinel, so a later boot can name the build
+ // that died even after an auto-update has replaced it.
+ appVersion: app.getVersion(),
// Deliver to one live window — focused first — and report undeliverable
// so the invitation waits for the next renderer-ready signal instead of
// dropping (at boot, or when the only window is the one that crashed).
diff --git a/packages/desktop/src/main/minidump-ownership.test.ts b/packages/desktop/src/main/minidump-ownership.test.ts
index c78e597a7..1b8ab82ea 100644
--- a/packages/desktop/src/main/minidump-ownership.test.ts
+++ b/packages/desktop/src/main/minidump-ownership.test.ts
@@ -16,9 +16,9 @@
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
-import { afterEach, describe, expect, test } from 'vitest';
+import { afterEach, describe, expect, test, vi } from 'vitest';
import { buildMinidump, type MinidumpPatch } from './minidump.test-helper.ts';
-import { classifyMinidumpOwnership } from './minidump-ownership.ts';
+import { classifyMinidumpOwnership, readMinidumpAppVersion } from './minidump-ownership.ts';
const tmpDirs: string[] = [];
@@ -175,28 +175,72 @@ describe('symlinked launch paths', () => {
/**
* Every case names a single lie the dump tells about its own layout, with the
* rest of the structure left well-formed, so a failure points at one offset.
+ *
+ * `versionSurvives` records what the SAME lie does to the app-version read,
+ * which lives in a different stream. A lie about the header or the stream
+ * directory takes down both reads; one about a module record leaves the
+ * annotations perfectly readable. That split is the observable form of the two
+ * reads being independent, so it is pinned per case rather than asserted as a
+ * blanket property neither read could violate.
*/
-const MALFORMED_CASES: Array<{ name: string; patch: MinidumpPatch }> = [
- { name: 'a wrong header magic', patch: { signature: 'XXXX' } },
- { name: 'a header truncated mid-field', patch: { truncateTo: 20 } },
+const MALFORMED_CASES: Array<{
+ name: string;
+ patch: MinidumpPatch;
+ versionSurvives: boolean;
+}> = [
+ { name: 'a wrong header magic', patch: { signature: 'XXXX' }, versionSurvives: false },
+ { name: 'a header truncated mid-field', patch: { truncateTo: 20 }, versionSurvives: false },
{
name: 'a stream-directory RVA past the end of the file',
patch: { streamDirectoryRva: 0xffff },
+ versionSurvives: false,
+ },
+ {
+ name: 'a stream count beyond the parser cap',
+ patch: { streamCount: 100_000 },
+ versionSurvives: false,
+ },
+ { name: 'a stream count of zero', patch: { streamCount: 0 }, versionSurvives: false },
+ {
+ name: 'a directory holding no ModuleList stream',
+ patch: { streamType: 7 },
+ versionSurvives: true,
},
- { name: 'a stream count beyond the parser cap', patch: { streamCount: 100_000 } },
- { name: 'a stream count of zero', patch: { streamCount: 0 } },
- { name: 'a directory holding no ModuleList stream', patch: { streamType: 7 } },
- { name: 'a ModuleList RVA past the end of the file', patch: { moduleListRva: 0xffff } },
- { name: 'a module count of zero', patch: { moduleCount: 0 } },
+ {
+ name: 'a ModuleList RVA past the end of the file',
+ patch: { moduleListRva: 0xffff },
+ versionSurvives: true,
+ },
+ { name: 'a module count of zero', patch: { moduleCount: 0 }, versionSurvives: true },
// The ModuleList count sits at 44..48 and the first 108-byte record follows,
// so cutting at 60 leaves the record short.
- { name: 'a first module record cut short by the file end', patch: { truncateTo: 60 } },
- { name: 'a module-name RVA past the end of the file', patch: { nameRva: 0xffff } },
- { name: 'a name byte length of zero', patch: { nameByteLength: 0 } },
- { name: 'an odd name byte length (never valid UTF-16)', patch: { nameByteLength: 9 } },
- { name: 'a name byte length beyond the parser cap', patch: { nameByteLength: 1_000_000 } },
+ {
+ name: 'a first module record cut short by the file end',
+ patch: { truncateTo: 60 },
+ versionSurvives: false,
+ },
+ {
+ name: 'a module-name RVA past the end of the file',
+ patch: { nameRva: 0xffff },
+ versionSurvives: true,
+ },
+ { name: 'a name byte length of zero', patch: { nameByteLength: 0 }, versionSurvives: true },
+ {
+ name: 'an odd name byte length (never valid UTF-16)',
+ patch: { nameByteLength: 9 },
+ versionSurvives: true,
+ },
+ {
+ name: 'a name byte length beyond the parser cap',
+ patch: { nameByteLength: 1_000_000 },
+ versionSurvives: true,
+ },
// Even and under the cap, but longer than the bytes actually present.
- { name: 'a name that overruns the end of the file', patch: { nameByteLength: 4096 } },
+ {
+ name: 'a name that overruns the end of the file',
+ patch: { nameByteLength: 4096 },
+ versionSurvives: true,
+ },
];
describe('malformed dumps are unreadable, never ours', () => {
@@ -231,3 +275,227 @@ describe('malformed dumps are unreadable, never ours', () => {
expect(classifyMinidumpOwnership(dir, join(dir, 'OpenKnowledge.app'))).toBe('unknown');
});
});
+
+/**
+ * The crashed session's own app version, which the boot-time detector needs
+ * because an auto-update can replace the binary between the crash and the
+ * launch that notices it.
+ *
+ * The security-relevant property mirrors the ownership one: no malformed
+ * annotation block may ever produce a version, none may throw on the boot
+ * path, and none may disturb the ownership answer read from the same file.
+ */
+describe('crashpad app-version annotations', () => {
+ /** Write a dump under a temp dir and read its version back. */
+ function versionOf(patch: MinidumpPatch): string | null {
+ const dir = makeDir();
+ const dumpPath = join(dir, 'crash.dmp');
+ writeFileSync(dumpPath, buildMinidump([ownModule(join(dir, 'OpenKnowledge.app'))], patch));
+ const read = readMinidumpAppVersion(dumpPath);
+ // Every case here is a dump the parse declines to trust, never one it
+ // failed to parse — the distinction the flag exists to carry, asserted
+ // once here so each case below can stay a plain version comparison.
+ expect(read.parseFailed).toBe(false);
+ return read.version;
+ }
+
+ test('a dump carrying annotations names the version that crashed', () => {
+ // The five keys a real Electron dump carries, in the order Crashpad
+ // writes them, so the lookup is exercised past the first entry.
+ expect(
+ versionOf({
+ annotations: {
+ _productName: 'OpenKnowledge',
+ _version: '0.41.0',
+ plat: 'OS X',
+ prod: 'Electron',
+ ver: '41.2.1',
+ },
+ }),
+ ).toBe('0.41.0');
+ });
+
+ test('the app version wins over the Electron version beside it', () => {
+ expect(versionOf({ annotations: { ver: '41.2.1', _version: '0.41.0' } })).toBe('0.41.0');
+ });
+
+ test('a dump with no crashpad stream at all has no version', () => {
+ expect(versionOf({})).toBeNull();
+ });
+
+ test('annotations that name no version have no version', () => {
+ expect(versionOf({ annotations: { _productName: 'OpenKnowledge', prod: 'Electron' } })).toBe(
+ null,
+ );
+ });
+
+ test('a dump truncated before its annotations has no version', () => {
+ expect(versionOf({ annotations: { _version: '0.41.0' }, truncateTo: 80 })).toBeNull();
+ });
+
+ /**
+ * One lie per case with the rest of the dump well-formed, so a failure names
+ * a single offset. Each uses a single-entry dictionary because the patches
+ * target the first entry.
+ */
+ const MALFORMED_ANNOTATION_CASES: Array<{ name: string; patch: MinidumpPatch }> = [
+ {
+ name: 'a crashpad stream hidden behind another stream type',
+ patch: { crashpadStreamType: 9 },
+ },
+ { name: 'a dictionary RVA of zero (no annotations registered)', patch: { annotationsRva: 0 } },
+ { name: 'a dictionary RVA past the end of the file', patch: { annotationsRva: 0xffff } },
+ { name: 'an entry count beyond the parser cap', patch: { annotationCount: 100_000 } },
+ { name: 'an entry count of zero', patch: { annotationCount: 0 } },
+ { name: 'an entry count larger than the block has room for', patch: { annotationCount: 4 } },
+ { name: 'a declared dictionary size too small for its entries', patch: { annotationsSize: 4 } },
+ { name: 'a key RVA past the end of the file', patch: { annotationKeyRva: 0xffff } },
+ { name: 'a key RVA of zero', patch: { annotationKeyRva: 0 } },
+ { name: 'a value RVA past the end of the file', patch: { annotationValueRva: 0xffff } },
+ { name: 'a value RVA of zero', patch: { annotationValueRva: 0 } },
+ { name: 'a value byte length of zero', patch: { annotationValueByteLength: 0 } },
+ {
+ name: 'a value byte length beyond the parser cap',
+ patch: { annotationValueByteLength: 1_000_000 },
+ },
+ // Under the cap, but longer than the bytes actually present.
+ {
+ name: 'a value that overruns the end of the file',
+ patch: { annotationValueByteLength: 200 },
+ },
+ ];
+
+ for (const { name, patch } of MALFORMED_ANNOTATION_CASES) {
+ test(`${name} yields no version`, () => {
+ expect(versionOf({ annotations: { _version: '0.41.0' }, ...patch })).toBeNull();
+ });
+ }
+
+ test('a value carrying control characters is refused', () => {
+ // The value lands in a line-oriented log and report body, so a newline
+ // would let it forge the context lines printed around it.
+ const forged = `0.41.0${String.fromCharCode(10)}Crash source: something untrue`;
+ expect(versionOf({ annotations: { _version: forged } })).toBeNull();
+ });
+
+ test('a malformed annotation block leaves ownership intact', () => {
+ // The load-bearing independence check. Ownership decides whether a report
+ // may carry process memory at all, so a drift in Crashpad's annotation
+ // layout must never quietly turn our own crashes into unattachable ones.
+ const dir = makeDir();
+ const bundleRoot = join(dir, 'Applications', 'OpenKnowledge.app');
+ const dumpPath = join(dir, 'crash.dmp');
+ writeFileSync(
+ dumpPath,
+ buildMinidump([ownModule(bundleRoot), '/usr/lib/dyld'], {
+ annotations: { _version: '0.41.0' },
+ annotationsRva: 0xffff,
+ }),
+ );
+
+ expect(readMinidumpAppVersion(dumpPath).version).toBeNull();
+ expect(classifyMinidumpOwnership(dumpPath, bundleRoot)).toBe('ours');
+ });
+
+ test('a version never launders a foreign dump into ours', () => {
+ // Crashpad stamps OUR annotations onto dumps written for descendant
+ // processes, so a version alone never implies the crash was ours. This is
+ // why the detector reads the version only for a dump ownership kept.
+ const dir = makeDir();
+ const bundleRoot = join(dir, 'Applications', 'OpenKnowledge.app');
+ const dumpPath = join(dir, 'crash.dmp');
+ writeFileSync(
+ dumpPath,
+ buildMinidump(['/Applications/LibreOffice.app/Contents/MacOS/soffice'], {
+ annotations: { _version: '0.41.0' },
+ }),
+ );
+
+ expect(readMinidumpAppVersion(dumpPath).version).toBe('0.41.0');
+ expect(classifyMinidumpOwnership(dumpPath, bundleRoot)).toBe('foreign');
+ });
+
+ test('an ownership lie decides the version read on its own merits', () => {
+ // Each case tells one structural lie and the version read answers for
+ // itself: the header and stream directory are shared, so a lie there takes
+ // both down, while a lie about a module record leaves the annotations in
+ // another stream untouched. Pinned as an exact table rather than "none of
+ // these throws", which the two catch-alls guarantee no matter what the
+ // parse does — though a throw still fails here, since it would take out
+ // boot-time crash detection.
+ const observed = MALFORMED_CASES.map(({ name, patch }) => {
+ const dir = makeDir();
+ const dumpPath = join(dir, 'crash.dmp');
+ writeFileSync(
+ dumpPath,
+ buildMinidump([ownModule(join(dir, 'OpenKnowledge.app'))], {
+ annotations: { _version: '0.41.0' },
+ ...patch,
+ }),
+ );
+ return { name, version: readMinidumpAppVersion(dumpPath).version };
+ });
+
+ // Compared as whole rows so a failure names the case that moved.
+ expect(observed).toEqual(
+ MALFORMED_CASES.map(({ name, versionSurvives }) => ({
+ name,
+ version: versionSurvives ? '0.41.0' : null,
+ })),
+ );
+ });
+
+ test('a parse that throws is reported as broken, not as an absent version', async () => {
+ // Nothing a dump can CONTAIN reaches the annotation parse's catch — every
+ // bound is checked and every distrusted layout declines by returning null,
+ // which is what the table above pins. What could reach it is a Crashpad
+ // revision whose records this parser no longer recognizes at all, and then
+ // the report shows an unknown version with nothing to say whether the dump
+ // predates the annotation or the parser regressed. Those are opposite
+ // investigations. Driving the throw from outside the file is the only way
+ // to hold the two apart, since no input can.
+ //
+ // The read is intercepted by its width: the Crashpad info record's 44-byte
+ // prefix opens the annotation walk, and no other read in either pass asks
+ // for that many bytes (the module-name block of a tmpdir path is far
+ // wider), so ownership stays on the real implementation throughout.
+ const CRASHPAD_INFO_PREFIX_BYTES = 44;
+ const dir = makeDir();
+ const bundleRoot = join(dir, 'OpenKnowledge.app');
+ const dumpPath = join(dir, 'crash.dmp');
+ writeFileSync(
+ dumpPath,
+ buildMinidump([ownModule(bundleRoot)], { annotations: { _version: '0.41.0' } }),
+ );
+
+ const realFs = await vi.importActual<typeof import('node:fs')>('node:fs');
+ vi.resetModules();
+ vi.doMock('node:fs', () => ({
+ ...realFs,
+ readSync: (
+ fd: number,
+ buffer: NodeJS.ArrayBufferView,
+ offset: number,
+ length: number,
+ position: number,
+ ) => {
+ if (length === CRASHPAD_INFO_PREFIX_BYTES) throw new Error('crashpad layout moved');
+ return realFs.readSync(fd, buffer, offset, length, position);
+ },
+ }));
+ try {
+ // Dynamic so it binds the mocked fs; the statically imported copy at the
+ // top of this file stays real for every other test here.
+ const mocked = await import('./minidump-ownership.ts');
+
+ expect(mocked.readMinidumpAppVersion(dumpPath)).toEqual({ version: null, parseFailed: true });
+ // And the containment holds: a broken annotation parse still costs the
+ // ownership answer nothing, which is what decides whether process memory
+ // may leave the machine.
+ expect(mocked.classifyMinidumpOwnership(dumpPath, bundleRoot)).toBe('ours');
+ } finally {
+ vi.doUnmock('node:fs');
+ vi.resetModules();
+ }
+ });
+});
diff --git a/packages/desktop/src/main/minidump-ownership.ts b/packages/desktop/src/main/minidump-ownership.ts
index bd4981a01..611fa44bf 100644
--- a/packages/desktop/src/main/minidump-ownership.ts
+++ b/packages/desktop/src/main/minidump-ownership.ts
@@ -38,6 +38,20 @@
* reported separately rather than folded in: on a crash that was plainly ours,
* it is the only thing that moves.
*
+ * A pass also lifts the app version Crashpad stamped into the dump, which is
+ * the version of the session that DIED — not the one asking. An auto-update
+ * between a crash and the next launch is exactly the case where those differ,
+ * and it is the reason the version cannot be taken from the running process.
+ *
+ * The two records are read together, but the two questions are exported
+ * separately, so a caller that wants both answers opens the file twice. That
+ * is the trade rather than an oversight: ownership decides whether a report
+ * may carry process memory at all, and a call whose only return value is the
+ * module path keeps the annotation side out of that answer structurally,
+ * instead of leaving it a rule somebody has to keep honoring. The annotation
+ * walk still runs on that pass — what is constrained is what it can reach, not
+ * whether it executes. The price is one extra open of one dump per boot.
+ *
* Reads only the handful of records it needs at explicit file offsets: a
* minidump is raw process memory and can be hundreds of megabytes, so it must
* never be slurped whole to answer a path question. No symbolizer, no Crashpad
@@ -45,6 +59,7 @@
*/
import { closeSync, openSync, readSync, realpathSync } from 'node:fs';
+import { asReportableAppVersion } from './crashed-app-version.ts';
import { isPathWithinProject } from './path-containment.ts';
/**
@@ -62,6 +77,7 @@ const NUMBER_OF_STREAMS_OFFSET = 8;
const STREAM_DIRECTORY_RVA_OFFSET = 12;
/** Directory entry: `(streamType u32, dataSize u32, rva u32)`. */
const DIRECTORY_ENTRY_BYTES = 12;
+const DIRECTORY_ENTRY_SIZE_OFFSET = 4;
const DIRECTORY_ENTRY_RVA_OFFSET = 8;
/** `ModuleListStream` in the minidump stream-type enum. */
const MODULE_LIST_STREAM_TYPE = 4;
@@ -69,7 +85,27 @@ const MODULE_RECORD_BYTES = 108;
const MODULE_NAME_RVA_OFFSET = 20;
/**
- * Ceilings on the two counts read out of the file before any allocation. A
+ * `MinidumpCrashpadInfo` — Crashpad's own stream, outside the minidump format's
+ * stream-type enum, carrying the annotations the crashing process registered.
+ * Its prefix is `version u32`, two 16-byte UUIDs (report id, client id), then
+ * the simple-annotation dictionary's `MINIDUMP_LOCATION_DESCRIPTOR`
+ * (`dataSize u32, rva u32`) — the last field this parse needs.
+ */
+const CRASHPAD_INFO_STREAM_TYPE = 0x4350_0001;
+const CRASHPAD_ANNOTATIONS_SIZE_OFFSET = 36;
+const CRASHPAD_ANNOTATIONS_RVA_OFFSET = 40;
+const CRASHPAD_INFO_PREFIX_BYTES = 44;
+/**
+ * `MinidumpSimpleStringDictionary`: an entry count followed by that many
+ * `(keyRva u32, valueRva u32)` pairs, each RVA naming a length-prefixed UTF-8
+ * string. Electron registers the app's own version under `_version`; the
+ * separate `ver` key holds Electron's, which is not what a triager wants.
+ */
+const ANNOTATION_ENTRY_BYTES = 8;
+const APP_VERSION_ANNOTATION_KEY = '_version';
+
+/**
+ * Ceilings on every count read out of the file before any allocation. A
* corrupt or hostile dump can name any u32 here, and a dump is untrusted input
* for exactly the reason this module exists: it may have been written for a
* process that is not ours.
@@ -77,6 +113,10 @@ const MODULE_NAME_RVA_OFFSET = 20;
const MAX_STREAMS = 4096;
/** Byte length of the UTF-16 module name; real executable paths are far shorter. */
const MAX_MODULE_NAME_BYTES = 8192;
+/** Real dumps carry a handful of annotations; this is room to spare, not a target. */
+const MAX_ANNOTATIONS = 256;
+/** Both keys and values: a version string is tens of bytes. */
+const MAX_ANNOTATION_STRING_BYTES = 256;
/** Exact positional read, or null when the file is shorter than the request. */
function readExactly(fd: number, length: number, position: number): Buffer | null {
@@ -85,52 +125,141 @@ function readExactly(fd: number, length: number, position: number): Buffer | nul
}
/**
- * Path of `ModuleList[0]` — the crashed process's main executable — or null
- * when the file is not a minidump we can read that far into.
+ * What one pass over a dump can establish about the process that died. Each
+ * record answers for itself: the two live in different streams, so an
+ * unreadable one never costs the other.
+ */
+interface MinidumpFacts {
+ /** Path of `ModuleList[0]`, the crashed process's main executable. */
+ mainModulePath: string | null;
+ /** The crashed process's own app version, from Crashpad's annotations. */
+ appVersion: string | null;
+ /**
+ * The annotation parse threw rather than declining. Nothing a dump can
+ * contain reaches that: every bound is checked and every layout the parse
+ * distrusts returns null instead. What could is a Crashpad revision this
+ * parser no longer recognizes at all — and a regressed parser reads exactly
+ * like a dump too old to carry the annotation unless it says otherwise.
+ */
+ appVersionParseFailed: boolean;
+}
+
+const NO_FACTS: MinidumpFacts = Object.freeze({
+ mainModulePath: null,
+ appVersion: null,
+ appVersionParseFailed: false,
+});
+
+/** A length-prefixed UTF-8 annotation string, bounded before it is allocated. */
+function readAnnotationString(fd: number, rva: number): string | null {
+ if (rva === 0) return null;
+ const length = readExactly(fd, 4, rva);
+ if (length === null) return null;
+ const byteLength = length.readUInt32LE(0);
+ if (byteLength === 0 || byteLength > MAX_ANNOTATION_STRING_BYTES) return null;
+ const bytes = readExactly(fd, byteLength, rva + 4);
+ return bytes === null ? null : bytes.toString('utf8');
+}
+
+/**
+ * The `_version` annotation paired with whether the walk below threw on the way
+ * to it. Never throws itself: the caller's other answer must survive anything
+ * found here, so a failure stays contained rather than unwinding the whole
+ * parse — and the flag is what keeps that containment from also being silent.
*/
-function readMainModulePath(dumpPath: string): string | null {
+function readAppVersionAnnotation(
+ fd: number,
+ infoRva: number,
+ infoSize: number,
+): { version: string | null; parseFailed: boolean } {
+ try {
+ return { version: parseAppVersionAnnotation(fd, infoRva, infoSize), parseFailed: false };
+ } catch {
+ return { version: null, parseFailed: true };
+ }
+}
+
+/**
+ * The annotation walk itself. Declines by returning null for every layout it
+ * distrusts; the caller above owns what happens if it throws anyway.
+ */
+function parseAppVersionAnnotation(fd: number, infoRva: number, infoSize: number): string | null {
+ if (infoSize < CRASHPAD_INFO_PREFIX_BYTES) return null;
+ const info = readExactly(fd, CRASHPAD_INFO_PREFIX_BYTES, infoRva);
+ if (info === null) return null;
+ // Crashpad spells "this dump registered no annotations" as a zero location,
+ // which is an ordinary state rather than a damaged one.
+ const dictRva = info.readUInt32LE(CRASHPAD_ANNOTATIONS_RVA_OFFSET);
+ if (dictRva === 0) return null;
+ const count = readExactly(fd, 4, dictRva);
+ if (count === null) return null;
+ const entryCount = count.readUInt32LE(0);
+ if (entryCount === 0 || entryCount > MAX_ANNOTATIONS) return null;
+ // The declared block must be large enough to hold the entries it claims.
+ // Checked as a floor rather than an equality so a future revision may pad
+ // the dictionary without the version silently going dark.
+ const declaredBytes = info.readUInt32LE(CRASHPAD_ANNOTATIONS_SIZE_OFFSET);
+ if (declaredBytes < 4 + entryCount * ANNOTATION_ENTRY_BYTES) return null;
+
+ const entries = readExactly(fd, entryCount * ANNOTATION_ENTRY_BYTES, dictRva + 4);
+ if (entries === null) return null;
+ for (let i = 0; i < entryCount; i += 1) {
+ const at = i * ANNOTATION_ENTRY_BYTES;
+ if (readAnnotationString(fd, entries.readUInt32LE(at)) !== APP_VERSION_ANNOTATION_KEY) {
+ continue;
+ }
+ return asReportableAppVersion(readAnnotationString(fd, entries.readUInt32LE(at + 4)));
+ }
+ return null;
+}
+
+/**
+ * Everything this module reads out of `dumpPath`, in one open and one walk of
+ * the stream directory.
+ */
+function readMinidumpFacts(dumpPath: string): MinidumpFacts {
let fd: number | null = null;
try {
fd = openSync(dumpPath, 'r');
const header = readExactly(fd, HEADER_BYTES, 0);
- if (header === null || header.readUInt32LE(0) !== MINIDUMP_SIGNATURE) return null;
+ if (header === null || header.readUInt32LE(0) !== MINIDUMP_SIGNATURE) return NO_FACTS;
const streamCount = header.readUInt32LE(NUMBER_OF_STREAMS_OFFSET);
- if (streamCount === 0 || streamCount > MAX_STREAMS) return null;
+ if (streamCount === 0 || streamCount > MAX_STREAMS) return NO_FACTS;
const directory = readExactly(
fd,
streamCount * DIRECTORY_ENTRY_BYTES,
header.readUInt32LE(STREAM_DIRECTORY_RVA_OFFSET),
);
- if (directory === null) return null;
+ if (directory === null) return NO_FACTS;
let moduleListRva: number | null = null;
+ let crashpadInfoRva: number | null = null;
+ let crashpadInfoSize = 0;
for (let i = 0; i < streamCount; i += 1) {
const at = i * DIRECTORY_ENTRY_BYTES;
- if (directory.readUInt32LE(at) === MODULE_LIST_STREAM_TYPE) {
+ const streamType = directory.readUInt32LE(at);
+ if (streamType === MODULE_LIST_STREAM_TYPE && moduleListRva === null) {
moduleListRva = directory.readUInt32LE(at + DIRECTORY_ENTRY_RVA_OFFSET);
- break;
+ } else if (streamType === CRASHPAD_INFO_STREAM_TYPE && crashpadInfoRva === null) {
+ crashpadInfoRva = directory.readUInt32LE(at + DIRECTORY_ENTRY_RVA_OFFSET);
+ crashpadInfoSize = directory.readUInt32LE(at + DIRECTORY_ENTRY_SIZE_OFFSET);
}
+ if (moduleListRva !== null && crashpadInfoRva !== null) break;
}
- if (moduleListRva === null) return null;
-
- const moduleCount = readExactly(fd, 4, moduleListRva);
- if (moduleCount === null || moduleCount.readUInt32LE(0) === 0) return null;
- const firstModule = readExactly(fd, MODULE_RECORD_BYTES, moduleListRva + 4);
- if (firstModule === null) return null;
-
- // A minidump string is a byte length followed by UTF-16LE units — the
- // length counts BYTES, not code units, so an odd value is malformed.
- const nameRva = firstModule.readUInt32LE(MODULE_NAME_RVA_OFFSET);
- const nameLength = readExactly(fd, 4, nameRva);
- if (nameLength === null) return null;
- const nameBytes = nameLength.readUInt32LE(0);
- if (nameBytes === 0 || nameBytes % 2 !== 0 || nameBytes > MAX_MODULE_NAME_BYTES) return null;
- const name = readExactly(fd, nameBytes, nameRva + 4);
- return name === null ? null : name.toString('utf16le');
+
+ const annotation =
+ crashpadInfoRva === null
+ ? null
+ : readAppVersionAnnotation(fd, crashpadInfoRva, crashpadInfoSize);
+ return {
+ mainModulePath: readMainModule(fd, moduleListRva),
+ appVersion: annotation?.version ?? null,
+ appVersionParseFailed: annotation?.parseFailed ?? false,
+ };
} catch {
// Unopenable file, torn read, permissions change mid-scan, or a corrupt
// dump — all mean the same thing to the caller.
- return null;
+ return NO_FACTS;
} finally {
if (fd !== null) {
try {
@@ -142,6 +271,24 @@ function readMainModulePath(dumpPath: string): string | null {
}
}
+function readMainModule(fd: number, moduleListRva: number | null): string | null {
+ if (moduleListRva === null) return null;
+ const moduleCount = readExactly(fd, 4, moduleListRva);
+ if (moduleCount === null || moduleCount.readUInt32LE(0) === 0) return null;
+ const firstModule = readExactly(fd, MODULE_RECORD_BYTES, moduleListRva + 4);
+ if (firstModule === null) return null;
+
+ // A minidump string is a byte length followed by UTF-16LE units — the
+ // length counts BYTES, not code units, so an odd value is malformed.
+ const nameRva = firstModule.readUInt32LE(MODULE_NAME_RVA_OFFSET);
+ const nameLength = readExactly(fd, 4, nameRva);
+ if (nameLength === null) return null;
+ const nameBytes = nameLength.readUInt32LE(0);
+ if (nameBytes === 0 || nameBytes % 2 !== 0 || nameBytes > MAX_MODULE_NAME_BYTES) return null;
+ const name = readExactly(fd, nameBytes, nameRva + 4);
+ return name === null ? null : name.toString('utf16le');
+}
+
/**
* Canonical spelling of `path`, or `path` unchanged when it resolves nowhere —
* a dump routinely outlives the binary that wrote it (deleted app, replaced
@@ -180,10 +327,40 @@ export function classifyMinidumpOwnership(
dumpPath: string,
appBundleRoot: string,
): MinidumpOwnership {
- const mainModule = readMainModulePath(dumpPath);
+ const mainModule = readMinidumpFacts(dumpPath).mainModulePath;
if (mainModule === null) return 'unknown';
const ours =
isPathWithinProject(canonicalize(mainModule), canonicalize(appBundleRoot), process.platform) ||
isPathWithinProject(mainModule, appBundleRoot, process.platform);
return ours ? 'ours' : 'foreign';
}
+
+export interface MinidumpAppVersionRead {
+ /**
+ * The app version of the session that wrote the dump, or null when the dump
+ * does not name one — an older build that predates the annotation, a dump
+ * truncated before its Crashpad stream, or a layout this parser no longer
+ * recognizes. Anything non-null already passed `asReportableAppVersion`, and
+ * null must be allowed to stay unknown.
+ */
+ version: string | null;
+ /**
+ * The parse threw. Separates "this dump has no version to give" from "the
+ * parser broke", which are otherwise the same null everywhere downstream and
+ * point an investigator in opposite directions.
+ */
+ parseFailed: boolean;
+}
+
+/**
+ * Read the app version of the session that wrote `dumpPath`.
+ *
+ * Only meaningful for a dump this app has not already disowned: Crashpad
+ * stamps OUR annotations onto dumps it writes for descendant processes, so a
+ * foreign dump carries our version while describing an unrelated program's
+ * death. Classify first.
+ */
+export function readMinidumpAppVersion(dumpPath: string): MinidumpAppVersionRead {
+ const facts = readMinidumpFacts(dumpPath);
+ return { version: facts.appVersion, parseFailed: facts.appVersionParseFailed };
+}
diff --git a/packages/desktop/src/main/minidump.test-helper.ts b/packages/desktop/src/main/minidump.test-helper.ts
index cb6be1615..3c41ec0d0 100644
--- a/packages/desktop/src/main/minidump.test-helper.ts
+++ b/packages/desktop/src/main/minidump.test-helper.ts
@@ -18,8 +18,22 @@ const DIRECTORY_ENTRY_BYTES = 12;
const MODULE_RECORD_BYTES = 108;
const MODULE_NAME_RVA_OFFSET = 20;
const MODULE_LIST_STREAM_TYPE = 4;
+const CRASHPAD_INFO_STREAM_TYPE = 0x4350_0001;
+/** Real dumps size this stream at 64 bytes; the parse reads only the first 44. */
+const CRASHPAD_INFO_BYTES = 64;
+const CRASHPAD_ANNOTATIONS_SIZE_OFFSET = 36;
+const CRASHPAD_ANNOTATIONS_RVA_OFFSET = 40;
+const ANNOTATION_ENTRY_BYTES = 8;
-/** Per-field overrides; each one corrupts a single value the parser reads. */
+/**
+ * Per-field overrides. Most corrupt a single value the parser reads;
+ * `annotations` instead adds a stream that is absent by default, so every
+ * fixture written before it existed stays byte-identical and keeps covering
+ * the dump-carries-no-annotations path for free.
+ *
+ * The annotation lies below all target the FIRST dictionary entry, so a case
+ * that exercises one should pass a single-entry `annotations` map.
+ */
export interface MinidumpPatch {
/** Header magic. Anything but `MDMP` must be refused outright. */
signature?: string;
@@ -46,11 +60,33 @@ export interface MinidumpPatch {
* single-entry directory it would only ever be exercised at index 0.
*/
streamsBefore?: number;
+ /**
+ * Crashpad simple annotations to carry. Omitted entirely when absent — no
+ * Crashpad stream is emitted at all, which is what a dump from a build
+ * predating them looks like.
+ */
+ annotations?: Record<string, string>;
+ /** Crashpad stream's directory type; anything else hides the annotations. */
+ crashpadStreamType?: number;
+ /** Crashpad info's pointer to the annotation dictionary; 0 means "none registered". */
+ annotationsRva?: number;
+ /** Crashpad info's claimed byte size for the dictionary block. */
+ annotationsSize?: number;
+ /** The dictionary's claimed entry count, independent of what it holds. */
+ annotationCount?: number;
+ /** First entry's pointer to its key string. */
+ annotationKeyRva?: number;
+ /** First entry's pointer to its value string. */
+ annotationValueRva?: number;
+ /** First entry's value block's claimed BYTE length. */
+ annotationValueByteLength?: number;
}
export function buildMinidump(modulePaths: string[], patch: MinidumpPatch = {}): Buffer {
const decoyStreams = patch.streamsBefore ?? 0;
- const directoryEntries = decoyStreams + 1;
+ const annotationEntries =
+ patch.annotations === undefined ? null : Object.entries(patch.annotations);
+ const directoryEntries = decoyStreams + 1 + (annotationEntries === null ? 0 : 1);
const directoryRva = HEADER_BYTES;
const moduleListRva = directoryRva + directoryEntries * DIRECTORY_ENTRY_BYTES;
const moduleListBytes = 4 + modulePaths.length * MODULE_RECORD_BYTES;
@@ -74,6 +110,53 @@ export function buildMinidump(modulePaths: string[], patch: MinidumpPatch = {}):
firstName.writeUInt32LE(patch.nameByteLength, 0);
}
+ // Crashpad's own stream, laid out after the module names: the fixed-size
+ // info record, then the dictionary of (key rva, value rva) pairs, then the
+ // strings those point at. Each string is a byte length that EXCLUDES the
+ // trailing NUL, the UTF-8 bytes, then that NUL — as real dumps write them.
+ const crashpadBlocks: Buffer[] = [];
+ const crashpadInfoRva = cursor;
+ if (annotationEntries !== null) {
+ const dictRva = crashpadInfoRva + CRASHPAD_INFO_BYTES;
+ const dictBytes = 4 + annotationEntries.length * ANNOTATION_ENTRY_BYTES;
+ const stringBlocks: Buffer[] = [];
+ let stringCursor = dictRva + dictBytes;
+ const appendString = (value: string): { rva: number; block: Buffer } => {
+ const encoded = Buffer.from(value, 'utf8');
+ const block = Buffer.alloc(4 + encoded.length + 1);
+ block.writeUInt32LE(encoded.length, 0);
+ encoded.copy(block, 4);
+ const rva = stringCursor;
+ stringBlocks.push(block);
+ stringCursor += block.length;
+ return { rva, block };
+ };
+
+ const dict = Buffer.alloc(dictBytes);
+ dict.writeUInt32LE(patch.annotationCount ?? annotationEntries.length, 0);
+ annotationEntries.forEach(([key, value], index) => {
+ const keyString = appendString(key);
+ const valueString = appendString(value);
+ const at = 4 + index * ANNOTATION_ENTRY_BYTES;
+ const first = index === 0;
+ dict.writeUInt32LE(first ? (patch.annotationKeyRva ?? keyString.rva) : keyString.rva, at);
+ dict.writeUInt32LE(
+ first ? (patch.annotationValueRva ?? valueString.rva) : valueString.rva,
+ at + 4,
+ );
+ if (first && patch.annotationValueByteLength !== undefined) {
+ valueString.block.writeUInt32LE(patch.annotationValueByteLength, 0);
+ }
+ });
+
+ const info = Buffer.alloc(CRASHPAD_INFO_BYTES);
+ info.writeUInt32LE(1, 0); // struct version — unread by this parse
+ info.writeUInt32LE(patch.annotationsSize ?? dictBytes, CRASHPAD_ANNOTATIONS_SIZE_OFFSET);
+ info.writeUInt32LE(patch.annotationsRva ?? dictRva, CRASHPAD_ANNOTATIONS_RVA_OFFSET);
+ crashpadBlocks.push(info, dict, ...stringBlocks);
+ cursor = stringCursor;
+ }
+
const header = Buffer.alloc(HEADER_BYTES);
header.write(patch.signature ?? 'MDMP', 0, 'ascii');
header.writeUInt32LE(0xa793, 4); // version — unread by the ownership parse
@@ -91,6 +174,12 @@ export function buildMinidump(modulePaths: string[], patch: MinidumpPatch = {}):
directory.writeUInt32LE(patch.streamType ?? MODULE_LIST_STREAM_TYPE, moduleListEntry);
directory.writeUInt32LE(moduleListBytes, moduleListEntry + 4);
directory.writeUInt32LE(patch.moduleListRva ?? moduleListRva, moduleListEntry + 8);
+ if (annotationEntries !== null) {
+ const crashpadEntry = moduleListEntry + DIRECTORY_ENTRY_BYTES;
+ directory.writeUInt32LE(patch.crashpadStreamType ?? CRASHPAD_INFO_STREAM_TYPE, crashpadEntry);
+ directory.writeUInt32LE(CRASHPAD_INFO_BYTES, crashpadEntry + 4);
+ directory.writeUInt32LE(crashpadInfoRva, crashpadEntry + 8);
+ }
const moduleList = Buffer.alloc(moduleListBytes);
moduleList.writeUInt32LE(patch.moduleCount ?? modulePaths.length, 0);
@@ -99,6 +188,6 @@ export function buildMinidump(modulePaths: string[], patch: MinidumpPatch = {}):
moduleList.writeUInt32LE(index === 0 ? (patch.nameRva ?? rva) : rva, at);
});
- const dump = Buffer.concat([header, directory, moduleList, ...nameBlocks]);
+ const dump = Buffer.concat([header, directory, moduleList, ...nameBlocks, ...crashpadBlocks]);
return patch.truncateTo === undefined ? dump : dump.subarray(0, patch.truncateTo);
}