Skip to content

Commit f9a65c2

Browse files
committed
fix(desktop): validate cross-arch app executable
1 parent 7a1e399 commit f9a65c2

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎scripts/build-desktop-artifact.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
ancestorNodeModulesPaths,
5050
copyDirectoryPreservingSymlinks,
5151
validateWindowsPackagedPayload,
52+
WindowsPrimaryNativeProbeError,
5253
WindowsPackagedPayloadValidationError,
5354
WINDOWS_PACKAGED_PAYLOAD_FILE_LIMIT,
5455
WINDOWS_SERVER_ASAR_IGNORE_GLOBS,
@@ -612,6 +613,34 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
612613
);
613614
});
614615

616+
it.effect("rejects a cross-architecture Windows payload without its primary executable", () =>
617+
Effect.scoped(
618+
Effect.gen(function* () {
619+
const fs = yield* FileSystem.FileSystem;
620+
const path = yield* Path.Path;
621+
const fixture = yield* makeWindowsPayloadFixture({ copyUnpackedNatives: true });
622+
const executablePath = path.join(fixture.packagedAppDir, fixture.appExecutableName);
623+
yield* fs.remove(executablePath);
624+
625+
const error = yield* validateWindowsPackagedPayload({
626+
stageDistDir: fixture.stageDistDir,
627+
appExecutableName: fixture.appExecutableName,
628+
targetArch: "arm64",
629+
}).pipe(Effect.flip);
630+
631+
assert.instanceOf(error, WindowsPrimaryNativeProbeError);
632+
assert.equal(error.executablePath, executablePath);
633+
}),
634+
).pipe(
635+
Effect.provide(
636+
Layer.mergeAll(
637+
Layer.succeed(HostProcessPlatform, "win32"),
638+
Layer.succeed(HostProcessArchitecture, "x64"),
639+
),
640+
),
641+
),
642+
);
643+
615644
it.effect("rejects a packaged sidecar whose ASAR-unpacked native is missing", () =>
616645
Effect.scoped(
617646
Effect.gen(function* () {

‎scripts/build-desktop-artifact.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,8 +2344,6 @@ export const verifyWindowsPrimaryFffNativeLoad = Effect.fn(
23442344
}) {
23452345
const hostPlatform = yield* HostProcessPlatform;
23462346
const hostArchitecture = yield* HostProcessArchitecture;
2347-
if (hostPlatform !== "win32" || hostArchitecture !== input.targetArch) return;
2348-
23492347
const fs = yield* FileSystem.FileSystem;
23502348
const path = yield* Path.Path;
23512349
const executablePath = path.join(input.packagedAppDir, input.appExecutableName);
@@ -2357,6 +2355,7 @@ export const verifyWindowsPrimaryFffNativeLoad = Effect.fn(
23572355
output: "The unpacked application does not contain its expected primary executable.",
23582356
});
23592357
}
2358+
if (hostPlatform !== "win32" || hostArchitecture !== input.targetArch) return;
23602359

23612360
const probeRoot = yield* fs.makeTempDirectoryScoped({
23622361
prefix: "t3code-windows-primary-native-probe-",

0 commit comments

Comments
 (0)