Windows NSIS uninstaller is corrupt when cross-built on Apple Silicon macOS (UninstallerReader slices 4 bytes short of the NSIS signature)

Author: ArtrixTechCreated Sep 29, 2026Updated Sep 29, 2026
  • Electron-Builder Version: 26.8.1 (also verified unchanged in 26.17.0 and 27.0.0-alpha.9)
  • Electron Updater (as-needed): not used — the NSIS installer itself is the update artifact
  • Node Version: v22.19.0
  • Electron Version: 35.7.5
  • Platform & Target: host macOS 26.4 arm64 (Apple Silicon), target Windows NSIS x64
  • Debug Logs: build succeeds with exit code 0 and no warnings; the defect surfaces only at uninstall/update time on Windows

Summary

A Windows NSIS installer cross-built on Apple Silicon macOS gets a corrupt uninstaller. A fresh install works. Uninstall fails with Installer integrity check has failed., and an overwrite update hangs forever.

UninstallerReader.exec() reconstructs the uninstaller by slicing the installer's PE image at nsisOffset, where nsisOffset is derived as Math.max(rawPointer + rawSize) over the section headers. On the installers I build, the real NSIS signature lives 4 bytes past that computed offset. The 4 truncated bytes corrupt the reconstructed uninstaller's internal CRC, so NSIS refuses to run it.

The build itself reports no error, because UninstallerReader validates its own NSIS block length field and never notices that the PE header was cut short.

Root cause

packages/app-builder-lib/src/targets/nsis/nsisUtil.ts:

typescript
let nsisOffset = 0
for (let i = 0; i < numberOfSections; i++) {
  const name = reader.string(8)
  reader.skip(8)
  const rawSize = reader.uint32()
  const rawPointer = reader.uint32()
  reader.skip(16)
  switch (name) {
    case ".text":
    case ".rdata":
    case ".data":
    case ".rsrc": {
      nsisOffset = Math.max(rawPointer + rawSize, nsisOffset)
      break
    }
    // ...
  }
}
const executable = buffer.subarray(0, nsisOffset)

rawPointer + rawSize gives the end of a section's raw data. The NSIS data begins after the section table, at a position that honours FileAlignment padding. On my installer these two values differ:

  .text    rawPointer=   1024 rawSize=  26624 end=  27648 <= counted
  .rdata   rawPointer=  27648 rawSize=   5632 end=  33280 <= counted
  .data    rawPointer=  33280 rawSize=   1536 end=  34816 <= counted
  .ndata   rawPointer=      0 rawSize=      0 end=      0
  .rsrc    rawPointer=  34816 rawSize=  23040 end=  57856 <= counted
  UninstallerReader computes nsisOffset = 57856
  actual NSIS signature offset         = 57860
  delta                                = 4

The reconstruct path then writes the truncated header followed by the inner block:

typescript
await fs.writeFile(uninstallerPath, executable)
await fs.appendFile(uninstallerPath, innerBuffer)

Resulting uninstaller: 140051 bytes, self-check fails. The same installer built natively on Windows produces 140052 bytes and a working uninstaller.

Why the code path is taken

NsisTarget.computeScriptAndSignUninstaller:

typescript
if (isMacOsCatalina()) {
  await UninstallerReader.exec(installerPath, uninstallerPath)
} else {
  await execWine(installerPath, null, [], { env: { __COMPAT_LAYER: "RunAsInvoker" } })
}

isMacOsCatalina() in packages/app-builder-lib/src/util/macosVersion.ts is process.platform === "darwin" && parseFloat(os.release()) >= 19.0.0. That is true for every macOS from Catalina onward, including macOS 26. Forcing the Wine branch is not a workaround on Apple Silicon either:

macOS Catalina doesn't support 32-bit executables and as result Wine cannot run Windows 32-bit applications too

NSIS needs 32-bit execution, which Apple Silicon lacks. The TODO: remove workaround when arm64 macOS has native wine support comment in NsisTarget.ts describes exactly this situation.

Impact

  1. The uninstaller exits immediately with code 2.
  2. installUtil.nsh's uninstallOldVersion retries 5 times.
  3. It then runs MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$(appCannotBeClosed)".
  4. With nobody present to answer, the installer blocks forever. /S does not suppress this dialog.

Net effect: installers built on Apple Silicon macOS can be installed once and can never be silently upgraded or uninstalled. This affects electron-updater flows on the same artifact as well.

Reproduction

bash
# host: macOS 26.4 arm64, electron-builder 26.8.1
npx electron-builder --win nsis --x64

On Windows, install it, then either run the installed uninstaller directly (it reports NSIS Error: Installer integrity check has failed.) or install a higher-version build over it (it hangs).

I can attach the installer or a minimum repro project if that is useful.

Observed evidence

Build host Uninstaller size sha256 Behaviour
macOS 26.4 arm64, cross-build 140051 D291B9C11E2EFEBE1C872533B113C5FC9D29C78EDB028E2F52EF8A5E5E201B04 exits code 2, integrity check failed
Windows 11 x64, native makensis 140052 85181EB65ED6BB30AFE85BE351550CC7AB3E3BC8B64BF25C97023909B6C8E3D2 integrity check passes, uninstall succeeds

I reproduced the same integrity failure on an unrelated product's installer built on the same Mac, which points at the build host and toolchain. One project's configuration is not the factor.

Still present in current releases

I unpacked the published packages to compare:

  • 26.17.0 — out/targets/nsis/nsisUtil.js contains the identical Math.max(rawPointer + rawSize, nsisOffset) computation.
  • 27.0.0-alpha.9 — the class moved to dist/targets/win/nsis/nsisUtil.js and the surrounding plumbing changed (macosVersion.js is gone, WineVmManager replaces execWine), while UninstallerReader.exec()'s body is byte-for-byte the same logic, including the subarray(0, nsisOffset) slice.

Related

This looks like the same defect reported in #4875 (Windows NSIS uninstall fails when built from MacOS Catalina, 2020), which was closed by the stale bot and carries the backlog label.

Suggested direction

Honour FileAlignment when computing the boundary, or locate the NSIS signature directly and slice there. A minimal change validating the approach:

typescript
const nsisSignature = [0xef, 0xbe, 0xad, 0xde, 0x4e, 0x75, 0x6c, 0x6c, 0x73, 0x6f, 0x66, 0x74, 0x49, 0x6e, 0x73, 0x74]
// nsisOffset currently lands 4 bytes before the real signature on some installers
const actualSignatureOffset = buffer.indexOf(Buffer.from(nsisSignature), Math.max(nsisOffset - 64, 0))
if (actualSignatureOffset !== -1) {
  nsisOffset = actualSignatureOffset
}

An additional safeguard would help here: after rebuilding the uninstaller, the writer could verify the artifact's own integrity check before the build reports success. A corrupt uninstaller would then fail the build, and the user's upgrade six months later would stay unaffected.

Workaround

Split the build: run the Electron packaging on macOS, then run the NSIS stage on Windows so makensis runs natively.

bash
# macOS
npx electron-builder --win --x64 --dir
powershell
# Windows, with build.electronVersion pinned in package.json
electron-builder.cmd --win nsis --x64 --prepackaged "...\win-unpacked"

Source: electron-userland/electron-builder