Repository navigation
fix: embed custom application manifests byte-for-byte instead of their entire backing ArrayBuffer - #1934
Merged
Conversation
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
marked this pull request as ready for review
July 16, 2026 04:45
MarshallOfSound
approved these changes
Jul 16, 2026
dsanders11
self-requested a review
July 16, 2026 05:18
dsanders11
reviewed
Jul 16, 2026
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); |
Member
There was a problem hiding this comment.
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
approved these changes
Jul 16, 2026
|
🎉 This PR is included in version 20.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Samuel Attard · Slack thread
Summarize your changes:
Before: packaging a Windows app with a custom manifest (
win32metadata: { 'application-manifest': ... }) produced an executable whose embeddedRT_MANIFESTresource 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", andsxstracereportsLine 0: XML Syntax error. Therequested-execution-leveloption had the same latent bug when rewriting the existing manifest.After: the embedded
RT_MANIFESTresource is exactly the bytes of the provided manifest file (or the rewritten execution-level manifest), and the packaged executable launches normally.How:
src/resedit.tshandedBuffer.from(...).bufferto the resource entry.Buffer.prototype.bufferis the entire backingArrayBuffer, 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'sbyteOffset/lengthrange. 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 withpe-library/resedit(no Electron download needed), run theresedit()step, read theRT_MANIFESTresource 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 nonzerobyteOffsetinto 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-levelbranch.Generated by Claude Code