Skip to content

fix: embed custom application manifests byte-for-byte instead of their entire backing ArrayBuffer - #1934

Merged
dsanders11 merged 4 commits into
mainfrom
fix/manifest-arraybuffer-slice
Jul 16, 2026
Merged

dsanders11 merged 4 commits into
mainfrom
fix/manifest-arraybuffer-slice

Conversation

@claude

@claude claude Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Requested by Samuel Attard · Slack thread

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:

Before: packaging a Windows app with a custom manifest (win32metadata: { 'application-manifest': ... }) produced an executable whose embedded RT_MANIFEST resource contained the manifest surrounded by arbitrary garbage bytes — whatever else happened to live in the Node Buffer pool at the time. Windows then refuses to launch the app with "The application has failed to start because its side-by-side configuration is incorrect", and sxstrace reports Line 0: XML Syntax error. The requested-execution-level option had the same latent bug when rewriting the existing manifest.

After: the embedded RT_MANIFEST resource is exactly the bytes of the provided manifest file (or the rewritten execution-level manifest), and the packaged executable launches normally.

How: src/resedit.ts handed Buffer.from(...).buffer to the resource entry. Buffer.prototype.buffer is the entire backing ArrayBuffer, and Node Buffers are usually views into a larger shared ArrayBuffer (the internal buffer pool), so this embedded the whole pool chunk instead of the manifest's byteOffset/length range. Both manifest branches now slice the backing ArrayBuffer to the Buffer's actual byte range, mirroring the ASAR integrity resource handling that already existed a few lines below in the same file.

The first commit adds regression tests that fail on main: they build a minimal fixture executable in-memory with pe-library/resedit (no Electron download needed), run the resedit() step, read the RT_MANIFEST resource back out, and assert it is byte-for-byte identical to the input. The manifest read is forced to be a Buffer view at a nonzero byteOffset into a larger backing ArrayBuffer so the tests deterministically guard this regression. On unfixed code, the read-back "manifest" was literally the contents of an unrelated file that had shared the buffer pool. The second commit is the fix.

Fixes #1933

Credit to @cristiammercado for the excellent diagnosis and the proposed fix in the issue report, including spotting the same pattern in the requested-execution-level branch.


Generated by Claude Code

claude added 2 commits July 16, 2026 01:41
Adds regression tests for #1933: builds a minimal fixture executable
in-memory with pe-library/resedit, runs the resedit() step with
win32metadata's application-manifest and requested-execution-level
options, and reads the RT_MANIFEST resource back out of the executable.

The manifest read is forced to be a Buffer view at a nonzero byteOffset
into a larger backing ArrayBuffer (the normal shape for pooled Buffers
in Node), so these tests fail on the current implementation, which
embeds the entire backing ArrayBuffer instead of the Buffer's actual
byte range.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016E9GNG9AcxUyvtEmRzovbj
Buffer.buffer returns the entire backing ArrayBuffer. Node Buffers are
frequently views into a larger shared ArrayBuffer (e.g. the internal
buffer pool), so embedding buffer.buffer as the RT_MANIFEST resource
can embed unrelated garbage bytes around the manifest, producing
executables that fail to launch with side-by-side configuration errors.

Slice the backing ArrayBuffer with byteOffset/length, mirroring the
existing ASAR integrity resource handling in the same file. Applies to
both the application-manifest and requested-execution-level branches.

Fixes #1933

Diagnosis and fix proposed by @cristiammercado in the issue report.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016E9GNG9AcxUyvtEmRzovbj
@MarshallOfSound
MarshallOfSound marked this pull request as ready for review July 16, 2026 04:45
@MarshallOfSound
MarshallOfSound requested a review from a team as a code owner July 16, 2026 04:45
@dsanders11
dsanders11 self-requested a review July 16, 2026 05:18
Comment thread test/resedit.spec.ts Outdated
Comment on lines +185 to +199
.mockImplementation(async function (this: unknown, ...args) {
const result = await (realReadFile as (...a: unknown[]) => Promise<unknown>).apply(
this,
args,
);
if (args[0] === manifestPath && Buffer.isBuffer(result)) {
const backing = Buffer.alloc(result.length + 128, '<lots of garbage bytes/>');
result.copy(backing, 64);
const view = backing.subarray(64, 64 + result.length);
expect(view.byteOffset).not.toBe(0);
expect(view.buffer.byteLength).toBeGreaterThan(view.length);
return view;
}
return result;
} as typeof promisifiedGracefulFs.readFile);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.mockImplementation(async function (this: unknown, ...args) {
const result = await (realReadFile as (...a: unknown[]) => Promise<unknown>).apply(
this,
args,
);
if (args[0] === manifestPath && Buffer.isBuffer(result)) {
const backing = Buffer.alloc(result.length + 128, '<lots of garbage bytes/>');
result.copy(backing, 64);
const view = backing.subarray(64, 64 + result.length);
expect(view.byteOffset).not.toBe(0);
expect(view.buffer.byteLength).toBeGreaterThan(view.length);
return view;
}
return result;
} as typeof promisifiedGracefulFs.readFile);
.mockImplementation(async function (this: unknown, ...args) {
const result = await realReadFile.apply(this, args);
if (args[0] === manifestPath && Buffer.isBuffer(result)) {
const backing = Buffer.alloc(result.length + 128, '<lots of garbage bytes/>');
result.copy(backing, 64);
const view = backing.subarray(64, 64 + result.length);
expect(view.byteOffset).not.toBe(0);
expect(view.buffer.byteLength).toBeGreaterThan(view.length);
return view;
}
return result;
});

The typing here seems unnecessarily complex.

@dsanders11
dsanders11 merged commit 2107e7c into main Jul 16, 2026
9 checks passed
@dsanders11
dsanders11 deleted the fix/manifest-arraybuffer-slice branch July 16, 2026 07:32
@electron-npm-package-publisher

Copy link
Copy Markdown

🎉 This PR is included in version 20.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom application manifest can be corrupted due to using Buffer.buffer without byteOffset

3 participants