You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "ggbdpq (via GitHub)" <gi...@apache.org> on 2026/10/20 16:00:54 UTC

[PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

ggbdpq opened a new pull request, #6200:
URL: https://github.com/apache/maka/pull/6200

   ## Summary
   
   Packaged macOS apps kept Electron's own Mach-O `LC_UUID` on every executable: electron-builder renames but never relinks, so all Electron 43 apps shared one identity (e.g. `4C4C4470-5555-3144-A124-518576DD11E3`). macOS 15+ local-network privacy (NECP) keys programs by the main executable's UUID, so Maka collided with every other Electron app — cross-app network-consent bleed and no settings entry of its own.
   
   This adds an `afterPack` hook (runs before code signing) that rewrites the 16-byte UUID payload of the main and every helper executable with UUIDv5 over `appId/executableName/cpuType`. It is deterministic (repackaging is stable, the rewrite is idempotent), changes no other byte, and never runs for Windows/Linux.
   
   ## Verification
   
   | Check | Result |
   |---|---|
   | `node --test scripts/macos-lc-uuid.test.mjs` | 7/7 pass (red before implementation: module not found) |
   | `node --test scripts/desktop-release-targets.test.mjs` | 4/4 pass |
   | `npm run format:check` | 2504 files, no fixes |
   | `npm run check:asf-headers` | 4588 covered, all headers present |
   | `apps/desktop` `npm run typecheck` | exit 0 |
   | Real fat Mach-O (`/bin/ls` copy) + `dwarfdump --uuid` | both slices rewritten, size unchanged, exactly 32 bytes differ, idempotent |
   | python3 `uuid.uuid5` cross-check | byte-identical values |
   | Full electron-builder package | not run locally (requires signing certificates; Electron binary download blocked). Hook exercised end-to-end on a real-binary bundle replica instead. |
   
   ## AI use
   
   Implemented by GLM-5.3-Flash (ZCode); human-reviewed.
   
   ## Checklist
   
   - [x] tests added
   - [x] format
   - [x] ASF headers
   - [x] no new dependencies
   - [ ] signed/notarized packaging run (CI release lane)
   
   Fixes #6026
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6295361231

   First-round CI red is mine, and it is fixed in `0fa32d6d0`: the CI test planner requires every suite named in `check:release` to reach a lane that runs that gate, and the new `macos-lc-uuid.test.mjs` matched no release-contract path (`reaches no releaseContract`). Registered the suite in `RELEASE_CONTRACT_FILES` next to its sibling packaged-app suites — `ci-test-plan.test.mjs` 40/40, full gate trio 51/51, format and ASF headers clean locally.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #6200:
URL: https://github.com/apache/maka/pull/6200#discussion_r4327462730


##########
scripts/macos-lc-uuid.test.mjs:
##########
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import assert from 'node:assert/strict';
+import { mkdir, mkdtemp, readFile, readdir, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { test } from 'node:test';
+import {
+  deterministicExecutableUuid,
+  machoLcUuidLocations,
+  rewriteBufferUuids,
+  rewritePackagedMacosUuids,
+  uuidv5,
+} from './macos-lc-uuid.mjs';
+
+/**
+ * Every packaged Mach-O keeps its byte length and load-command layout; only
+ * the 16 bytes under each LC_UUID move. These fixtures are the smallest
+ * headers that prove that: one LC_UUID and one unrelated load command whose
+ * bytes must survive untouched.
+ */
+const MH_MAGIC_64 = 0xfeedfacf;
+const LC_UUID = 0x1b;
+const LC_SOURCE_VERSION = 0x2a;
+const CPU_TYPE_X86_64 = 0x01000007;
+const CPU_TYPE_ARM64 = 0x0100000c;
+const DNS_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
+
+// The UUID from the issue: every Electron 43.4.1-based app ships this exact
+// Mach-O UUID, which is what makes macOS local-network privacy collide.
+const OLD_UUID = Buffer.from('4c4c447055553144a124518576dd11e3', 'hex');
+
+function thinMachO(cpuType, uuid) {
+  const header = Buffer.alloc(32);
+  header.writeUInt32LE(MH_MAGIC_64, 0);
+  header.writeUInt32LE(cpuType, 4);
+  header.writeUInt32LE(2, 12); // MH_EXECUTE
+  header.writeUInt32LE(2, 16); // ncmds
+  header.writeUInt32LE(24 + 16, 20); // sizeofcmds
+  const uuidCommand = Buffer.alloc(24);
+  uuidCommand.writeUInt32LE(LC_UUID, 0);
+  uuidCommand.writeUInt32LE(24, 4);
+  uuid.copy(uuidCommand, 8);
+  const sourceVersion = Buffer.alloc(16);
+  sourceVersion.writeUInt32LE(LC_SOURCE_VERSION, 0);
+  sourceVersion.writeUInt32LE(16, 4);
+  sourceVersion.writeBigUInt64LE(0x1122334455667788n, 8);
+  return Buffer.concat([header, uuidCommand, sourceVersion]);
+}
+
+function fatMachO(slices) {
+  const sliceSize = 4096;
+  const tableSize = 8 + slices.length * 20;
+  const buffer = Buffer.alloc(tableSize + slices.length * sliceSize);
+  buffer.writeUInt32BE(0xcafebabe, 0);
+  buffer.writeUInt32BE(slices.length, 4);
+  slices.forEach((slice, index) => {
+    const arch = 8 + index * 20;
+    const offset = tableSize + index * sliceSize;
+    buffer.writeUInt32BE(slice.cpuType, arch);
+    buffer.writeUInt32BE(offset, arch + 8);
+    buffer.writeUInt32BE(slice.data.length, arch + 12);
+    buffer.writeUInt32BE(12, arch + 16); // 2^12 slice alignment
+    slice.data.copy(buffer, offset);
+  });
+  return buffer;
+}
+
+/** Rewrites `buffer` and asserts everything but the UUID payloads survived. */
+function rewrittenLike(original, appId, executableName, uuidFor) {
+  const rewritten = Buffer.from(original);
+  const expected = Buffer.from(original);
+  const locations = machoLcUuidLocations(rewritten);
+  assert.ok(locations.length > 0, 'fixture must carry an LC_UUID');
+  for (const { offset, cpuType } of locations) {
+    const uuid = uuidFor(cpuType);
+    rewritten.write(uuid.replaceAll('-', ''), offset, 'hex');
+    expected.write(uuid.replaceAll('-', ''), offset, 'hex');
+  }
+  rewriteBufferUuids(rewritten, appId, executableName);
+  assert.equal(rewritten.length, original.length, 'file size must not change');
+  assert.deepEqual(rewritten, expected, 'only LC_UUID payloads may move');
+  return { rewritten, locations };
+}
+
+test('uuidv5 follows RFC 4122', () => {
+  // python.org under the DNS namespace is the reference example every
+  // conforming implementation agrees on (verified against python's uuid5).
+  assert.equal(uuidv5(DNS_NAMESPACE, 'python.org'), '886313e1-3b8a-5372-9b90-0c9aee199e5d');
+  assert.match(uuidv5(DNS_NAMESPACE, 'example.org'), /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);

Review Comment:
   [P2] Format the new test so CI can pass
   
   Exact-head [CI run 39454504056](https://github.com/apache/maka/actions/runs/39454504056) fails in `Check formatting` on this new file. Both the targeted Biome format check and the full local format check reproduce it; the full check reports this as its only error. Apply the formatter to this test and rerun CI. The planner registration in the second commit does not fix this remaining failure.
   



##########
scripts/macos-lc-uuid.mjs:
##########
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Rewrites the LC_UUID load command of every Mach-O in a packaged macOS app
+ * bundle (#6026).
+ *
+ * electron-builder renames Electron's executable files but never relinks them,
+ * so every shipped binary keeps the UUID burned into it by Electron's build:
+ * identical across every Electron app of the same version. macOS 15+ local-
+ * network privacy (NECP) identifies a program by its main executable's
+ * LC_UUID, so Maka shares a privacy identity with every other Electron 43
+ * install and never gets an entry of its own.
+ *
+ * The replacement is UUIDv5 (SHA-1, RFC 4122) over the app id, the executable
+ * file name and the slice's CPU type — deterministic, so repackaging the same
+ * inputs yields the same identity, and running the rewrite twice changes
+ * nothing. It runs from the `afterPack` hook, which is before code signing:
+ * the signature then covers the rewritten bytes, and notarization sees a
+ * self-consistent bundle.
+ */
+
+import { createHash } from 'node:crypto';
+import { readFile, readdir, writeFile } from 'node:fs/promises';
+import { basename, join } from 'node:path';
+
+const MH_MAGIC_64 = 0xfeedfacf;
+// Fat headers store their magic big-endian, so a little-endian read of
+// 0xcafebabe / 0xcafebabf yields the swapped values below.
+const FAT_MAGICS = new Map([
+  [0xbebafeca, { archEntrySize: 20 }],
+  [0xbfbafeca, { archEntrySize: 32 }],
+]);
+const LC_UUID = 0x1b;
+const MACHO_HEADER_64_SIZE = 32;
+const LOAD_COMMAND_HEADER_SIZE = 8;
+const UUID_SIZE = 16;
+
+// RFC 4122 Appendix C.1 namespace for fully-qualified domain names.
+const DNS_NAMESPACE_UUID = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
+// Derived, not invented: no magic constant here needs to be trusted, only the
+// project domain this namespace is pulled from.
+const MAKA_UUID_NAMESPACE = uuidv5(DNS_NAMESPACE_UUID, 'maka.apache.org');
+
+// The cputypes that actually appear in an Electron fat binary. arm64e shares
+// the ARM64 cputype and differs only in cpusubtype, so it is not
+// distinguishable — and not distinguishable is fine, because Electron ships
+// no arm64e slices; anything unexpected still gets a stable name via the
+// fallback below.
+const CPU_TYPE_NAMES = new Map([
+  [0x01000007, 'x86_64'],
+  [0x0100000c, 'arm64'],
+]);
+
+export function uuidv5(namespaceUuid, name) {
+  const digest = createHash('sha1')
+    .update(Buffer.from(namespaceUuid.replaceAll('-', ''), 'hex'))
+    .update(name, 'utf8')
+    .digest();
+  digest[6] = (digest[6] & 0x0f) | 0x50; // version 5
+  digest[8] = (digest[8] & 0x3f) | 0x80; // RFC 4122 variant
+  const hex = digest.toString('hex', 0, 16);
+  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
+}
+
+function cpuTypeName(cpuType) {
+  return CPU_TYPE_NAMES.get(cpuType) ?? `cpu-0x${cpuType.toString(16)}`;
+}
+
+/**
+ * The deterministic replacement UUID for one executable slice: distinct per
+ * app, per executable and per architecture, yet stable across rebuilds.
+ */
+export function deterministicExecutableUuid(appId, executableName, cpuType) {
+  // '/' cannot appear in a file name, so the joined name is unambiguous.
+  return uuidv5(MAKA_UUID_NAMESPACE, `${appId}/${executableName}/${cpuTypeName(cpuType)}`);

Review Comment:
   [P2] Preserve native build identity when rewriting the UUID
   
   Using only these three inputs makes every native build with the same app ID/name/architecture advertise the same build UUID. I ran the configured hook on official Electron 43.4.1 and 43.5.0 arm64 executables renamed to `Maka`: their different original UUIDs both become `a16a76f5-7ae2-54c5-9b4b-0032949b1d91`; all four helpers collide too. The official 43.5.0 symbol IDs match 5/5 originals and 0/5 rewritten executables. Native build UUIDs must distinguish different images and retain a corresponding symbol identity, as described in [Apple TN3178](https://developer.apple.com/documentation/technotes/tn3178-checking-for-and-resolving-build-uuid-problems). Include a native-build discriminator and retain a mapping or matching symbols for the rewritten IDs, so crash diagnostics can select the right native build.
   



##########
scripts/macos-lc-uuid.test.mjs:
##########
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import assert from 'node:assert/strict';
+import { mkdir, mkdtemp, readFile, readdir, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { test } from 'node:test';
+import {
+  deterministicExecutableUuid,
+  machoLcUuidLocations,
+  rewriteBufferUuids,
+  rewritePackagedMacosUuids,
+  uuidv5,
+} from './macos-lc-uuid.mjs';
+
+/**
+ * Every packaged Mach-O keeps its byte length and load-command layout; only
+ * the 16 bytes under each LC_UUID move. These fixtures are the smallest
+ * headers that prove that: one LC_UUID and one unrelated load command whose
+ * bytes must survive untouched.
+ */
+const MH_MAGIC_64 = 0xfeedfacf;
+const LC_UUID = 0x1b;
+const LC_SOURCE_VERSION = 0x2a;
+const CPU_TYPE_X86_64 = 0x01000007;
+const CPU_TYPE_ARM64 = 0x0100000c;
+const DNS_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
+
+// The UUID from the issue: every Electron 43.4.1-based app ships this exact
+// Mach-O UUID, which is what makes macOS local-network privacy collide.
+const OLD_UUID = Buffer.from('4c4c447055553144a124518576dd11e3', 'hex');
+
+function thinMachO(cpuType, uuid) {
+  const header = Buffer.alloc(32);
+  header.writeUInt32LE(MH_MAGIC_64, 0);
+  header.writeUInt32LE(cpuType, 4);
+  header.writeUInt32LE(2, 12); // MH_EXECUTE
+  header.writeUInt32LE(2, 16); // ncmds
+  header.writeUInt32LE(24 + 16, 20); // sizeofcmds
+  const uuidCommand = Buffer.alloc(24);
+  uuidCommand.writeUInt32LE(LC_UUID, 0);
+  uuidCommand.writeUInt32LE(24, 4);
+  uuid.copy(uuidCommand, 8);
+  const sourceVersion = Buffer.alloc(16);
+  sourceVersion.writeUInt32LE(LC_SOURCE_VERSION, 0);
+  sourceVersion.writeUInt32LE(16, 4);
+  sourceVersion.writeBigUInt64LE(0x1122334455667788n, 8);
+  return Buffer.concat([header, uuidCommand, sourceVersion]);
+}
+
+function fatMachO(slices) {
+  const sliceSize = 4096;
+  const tableSize = 8 + slices.length * 20;
+  const buffer = Buffer.alloc(tableSize + slices.length * sliceSize);
+  buffer.writeUInt32BE(0xcafebabe, 0);
+  buffer.writeUInt32BE(slices.length, 4);
+  slices.forEach((slice, index) => {
+    const arch = 8 + index * 20;
+    const offset = tableSize + index * sliceSize;
+    buffer.writeUInt32BE(slice.cpuType, arch);
+    buffer.writeUInt32BE(offset, arch + 8);
+    buffer.writeUInt32BE(slice.data.length, arch + 12);
+    buffer.writeUInt32BE(12, arch + 16); // 2^12 slice alignment
+    slice.data.copy(buffer, offset);
+  });
+  return buffer;
+}
+
+/** Rewrites `buffer` and asserts everything but the UUID payloads survived. */
+function rewrittenLike(original, appId, executableName, uuidFor) {
+  const rewritten = Buffer.from(original);
+  const expected = Buffer.from(original);
+  const locations = machoLcUuidLocations(rewritten);
+  assert.ok(locations.length > 0, 'fixture must carry an LC_UUID');
+  for (const { offset, cpuType } of locations) {
+    const uuid = uuidFor(cpuType);
+    rewritten.write(uuid.replaceAll('-', ''), offset, 'hex');

Review Comment:
   P3: writing the expected UUID into `rewritten` before calling `rewriteBufferUuids` makes the thin, fat and idempotence assertions pass even if the rewrite is a no-op. I confirmed this by replacing the `.copy(buffer, offset)` with a no-op: only the afterPack test failed. Write the expected bytes into `expected` only.



##########
scripts/macos-lc-uuid.mjs:
##########
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Rewrites the LC_UUID load command of every Mach-O in a packaged macOS app

Review Comment:
   P3: this says every Mach-O in the bundle is rewritten, but only regular files under `*.app/Contents/MacOS` are. `Electron Framework`, the dylibs, `chrome_crashpad_handler` and ShipIt keep Electron's UUIDs. That is fine for NECP, but the comment should say so. A line on the trade-off would also help: one UUID across all Maka versions means Electron's published dSYMs no longer match these executables.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6382166672

   Both red lanes on the merge trace to one upstream issue, not to this branch: `npm ls` reports `invalid: undici@7.30.1 ... @jackwener/opencli/node_modules/undici` (ELSPROBLEMS) — opencli 1.8.8 pins undici 7.29.1, and the RC2 dependency preparation (#6236) moved the tree to 7.30.1. My merge takes `package-lock.json` verbatim from main, so the branch carries exactly main's tree; main itself does not run the lanes that surface this (`check:artifact-budget` and the audit both fail on the same ELSPROBLEMS). The branch's own diff against main is still just the one `check:release` registration line plus the merge commit. Fixing it belongs to the upstream dependency work (bump opencli or re-pin undici), so I'm leaving it here rather than patching `overrides` from a feature branch. Local planner (40/40) and format checks are green on the merge.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6481757779

   Heads-up on CI: the `audit` lane is red at this head, but it predates the pin fix — the previous head (`eecb655b1`) fails the same way. The finding is `qs@6.16.0` (moderate, [GHSA-6pq8-jhm2-2vcw](https://github.com/advisories/GHSA-6pq8-jhm2-2vcw)) in the shipped-closure audit — unrelated to the undici override this branch touches. Leaving the bump decision to maintainers since qs is not part of this PR's change surface.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6480936155

   The upstream sync merge resolved the `package.json` conflict with the stale branch-side pin, leaving the `@jackwener/opencli@1.8.8` undici override at 7.29.1 while `package-lock.json` kept the upstream 7.30.1 resolution — an inconsistent state that would fail `npm ci`.
   
   43ae3cf3b restores the pin to 7.30.1, matching upstream/main (eeeae5128, #6236) byte for byte. The lockfile already resolved 7.30.1 and is byte-identical to the one at the merge's upstream parent, so no lock changes were needed; `npm install` confirms the tree is in sync.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6304048929

   Second red also mine, fixed in `77eeeea14`: three assertions in `macos-lc-uuid.test.mjs` needed reflowing (the suite was compressed after the earlier format pass without re-running it). `npm run format:check` verified clean on the full tree this time, suite still 7/7.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6345672632

   All four findings are addressed in `465ec366b`:
   
   - **[P2] Native build identity** — the slice's original UUID now feeds the UUIDv5 derivation (TN3178 discriminator), and the hook writes `lc-uuid-map.json` next to the bundle so the published Electron dSYMs still symbolicate rewritten executables. A new assertion pins that different originals derive different replacements.
   - **[P2] Formatting** — both files are `biome format` clean.
   - **[P3] Assertion strictness** — only `expected` receives the target bytes; verified a no-op `.copy` now fails the thin/fat/determinism assertions (previously only the afterPack test caught it).
   - **[P3] Comment accuracy** — the header now states the real scope and the dSYM trade-off.
   
   One honest contract change: with the original UUID inside the hash, a rewritten buffer fed through the rewrite again derives a different (still stable) identity, so the old "idempotent" test is now "repackaging the same Electron dist yields the same identity" — which is what the hook's real flow guarantees (every build starts from the pristine dist).
   
   Verification: `node --test scripts/macos-lc-uuid.test.mjs` 9/9 (new map assertion red before the fix: ENOENT), no-op probe red, `biome check` + `oxlint` clean on both files, `npm run check:asf-headers` green, `merge-tree` against current upstream/main conflict-free.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on code in PR #6200:
URL: https://github.com/apache/maka/pull/6200#discussion_r4350799738


##########
scripts/macos-lc-uuid.mjs:
##########
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Rewrites the LC_UUID load command of every Mach-O in a packaged macOS app

Review Comment:
   Fixed in `465ec366b` — the header comment states the actual scope (regular files under `*.app/Contents/MacOS`; `Electron Framework`, the dylibs, `chrome_crashpad_handler` and ShipIt keep Electron's UUIDs, which keeps their crash symbolication unchanged) and the trade-off: Electron's published dSYMs no longer match the rewritten executables, which the `lc-uuid-map.json` mapping compensates for.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6345614509

   Following up on my Oct 20 heads-up (the third red): instead of waiting for a separate dependency-bump PR, I merged `upstream/main` (`59f61cf7`) into this branch — head is now `87d3b36db`. Three days later no bump has landed upstream, `main`'s own `Dependency audit` lane is green, and it already carries exactly the patched versions the advisories need (`follow-redirects@1.16.1`, `hono@4.13.13`, MCP client 2.3.0 patch rebase). Merging moves the PR's baseline without touching its diff (this PR's files were untouched by the merge; no conflicts).
   
   **Verification** (local, macOS): `node scripts/audit-shipped-dependencies.mjs` against the official registry — `product shipped closure: 342 packages; advisories reaching it at moderate or above: 0`; `node --test scripts/macos-lc-uuid.test.mjs` 7/7; `node --test scripts/desktop-release-targets.test.mjs` 4/4; biome format check clean on the touched scripts. The audit lane should go green on this head.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6304130517

   Heads-up on the third red, which is not from this branch: the `Dependency audit` lane now fails on four advisories npm published after this PR's first two runs (`@modelcontextprotocol/client` GHSA-6prh-2h8m-c8cw, `@modelcontextprotocol/server` GHSA-jm63-cq47-j5jp/GHSA-46jr-4wx8-v453/GHSA-rvq5-wwqv-78pq, `follow-redirects` GHSA-q3jh-wrc6-jgq8/GHSA-8r9p-f939-6h3c, `hono` GHSA-5r4p-p66f-jhc7). This PR touches no dependencies (one planner-registry line + one reformat), the same lane was green on this PR's earlier heads and on `main` ~20h ago, and all four packages are pre-existing shipped closures — so the fix belongs to a dependency-bump PR, not here.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on PR #6200:
URL: https://github.com/apache/maka/pull/6200#issuecomment-6376266499

   Responding to the two loose ends in your 10-22 review:
   
   - **lc-uuid-map.json retention (P3)** — confirmed: current Nightly staging copies only declared payloads, so the map is not durably retained today. Treating that as release-engineering follow-up rather than expanding this PR: the right home is a declared staging payload (or a diagnostics artifact lane) alongside the update feed, and it should land with the release-workflow owners' sign-off. Noted here so it doesn't get lost.
   - **PR description wording** — updated: the description now reflects the original-UUID discriminator and the per-dist determinism semantics instead of the old idempotence phrasing.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): rewrite packaged macOS LC_UUIDs in an afterPack hook [maka]

Posted by "ggbdpq (via GitHub)" <gi...@apache.org>.
ggbdpq commented on code in PR #6200:
URL: https://github.com/apache/maka/pull/6200#discussion_r4350797680


##########
scripts/macos-lc-uuid.mjs:
##########
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Rewrites the LC_UUID load command of every Mach-O in a packaged macOS app
+ * bundle (#6026).
+ *
+ * electron-builder renames Electron's executable files but never relinks them,
+ * so every shipped binary keeps the UUID burned into it by Electron's build:
+ * identical across every Electron app of the same version. macOS 15+ local-
+ * network privacy (NECP) identifies a program by its main executable's
+ * LC_UUID, so Maka shares a privacy identity with every other Electron 43
+ * install and never gets an entry of its own.
+ *
+ * The replacement is UUIDv5 (SHA-1, RFC 4122) over the app id, the executable
+ * file name and the slice's CPU type — deterministic, so repackaging the same
+ * inputs yields the same identity, and running the rewrite twice changes
+ * nothing. It runs from the `afterPack` hook, which is before code signing:
+ * the signature then covers the rewritten bytes, and notarization sees a
+ * self-consistent bundle.
+ */
+
+import { createHash } from 'node:crypto';
+import { readFile, readdir, writeFile } from 'node:fs/promises';
+import { basename, join } from 'node:path';
+
+const MH_MAGIC_64 = 0xfeedfacf;
+// Fat headers store their magic big-endian, so a little-endian read of
+// 0xcafebabe / 0xcafebabf yields the swapped values below.
+const FAT_MAGICS = new Map([
+  [0xbebafeca, { archEntrySize: 20 }],
+  [0xbfbafeca, { archEntrySize: 32 }],
+]);
+const LC_UUID = 0x1b;
+const MACHO_HEADER_64_SIZE = 32;
+const LOAD_COMMAND_HEADER_SIZE = 8;
+const UUID_SIZE = 16;
+
+// RFC 4122 Appendix C.1 namespace for fully-qualified domain names.
+const DNS_NAMESPACE_UUID = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
+// Derived, not invented: no magic constant here needs to be trusted, only the
+// project domain this namespace is pulled from.
+const MAKA_UUID_NAMESPACE = uuidv5(DNS_NAMESPACE_UUID, 'maka.apache.org');
+
+// The cputypes that actually appear in an Electron fat binary. arm64e shares
+// the ARM64 cputype and differs only in cpusubtype, so it is not
+// distinguishable — and not distinguishable is fine, because Electron ships
+// no arm64e slices; anything unexpected still gets a stable name via the
+// fallback below.
+const CPU_TYPE_NAMES = new Map([
+  [0x01000007, 'x86_64'],
+  [0x0100000c, 'arm64'],
+]);
+
+export function uuidv5(namespaceUuid, name) {
+  const digest = createHash('sha1')
+    .update(Buffer.from(namespaceUuid.replaceAll('-', ''), 'hex'))
+    .update(name, 'utf8')
+    .digest();
+  digest[6] = (digest[6] & 0x0f) | 0x50; // version 5
+  digest[8] = (digest[8] & 0x3f) | 0x80; // RFC 4122 variant
+  const hex = digest.toString('hex', 0, 16);
+  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
+}
+
+function cpuTypeName(cpuType) {
+  return CPU_TYPE_NAMES.get(cpuType) ?? `cpu-0x${cpuType.toString(16)}`;
+}
+
+/**
+ * The deterministic replacement UUID for one executable slice: distinct per
+ * app, per executable and per architecture, yet stable across rebuilds.
+ */
+export function deterministicExecutableUuid(appId, executableName, cpuType) {
+  // '/' cannot appear in a file name, so the joined name is unambiguous.
+  return uuidv5(MAKA_UUID_NAMESPACE, `${appId}/${executableName}/${cpuTypeName(cpuType)}`);

Review Comment:
   Fixed in `465ec366b` — the slice's ORIGINAL UUID now feeds the UUIDv5 derivation as the native-build discriminator (TN3178): two Electron builds rewritten to the same app stay distinguishable, and the same dist still yields a stable identity across repackaging. The afterPack hook also writes `lc-uuid-map.json` next to the bundle mapping every original UUID to its replacement, so the published Electron dSYMs symbolicate the rewritten executables. A new assertion pins that two different originals derive different replacements, and the idempotence test now states its real contract (same pristine dist → same identity; a rewritten buffer fed back in derives a new one by design).



##########
scripts/macos-lc-uuid.test.mjs:
##########
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import assert from 'node:assert/strict';
+import { mkdir, mkdtemp, readFile, readdir, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { test } from 'node:test';
+import {
+  deterministicExecutableUuid,
+  machoLcUuidLocations,
+  rewriteBufferUuids,
+  rewritePackagedMacosUuids,
+  uuidv5,
+} from './macos-lc-uuid.mjs';
+
+/**
+ * Every packaged Mach-O keeps its byte length and load-command layout; only
+ * the 16 bytes under each LC_UUID move. These fixtures are the smallest
+ * headers that prove that: one LC_UUID and one unrelated load command whose
+ * bytes must survive untouched.
+ */
+const MH_MAGIC_64 = 0xfeedfacf;
+const LC_UUID = 0x1b;
+const LC_SOURCE_VERSION = 0x2a;
+const CPU_TYPE_X86_64 = 0x01000007;
+const CPU_TYPE_ARM64 = 0x0100000c;
+const DNS_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
+
+// The UUID from the issue: every Electron 43.4.1-based app ships this exact
+// Mach-O UUID, which is what makes macOS local-network privacy collide.
+const OLD_UUID = Buffer.from('4c4c447055553144a124518576dd11e3', 'hex');
+
+function thinMachO(cpuType, uuid) {
+  const header = Buffer.alloc(32);
+  header.writeUInt32LE(MH_MAGIC_64, 0);
+  header.writeUInt32LE(cpuType, 4);
+  header.writeUInt32LE(2, 12); // MH_EXECUTE
+  header.writeUInt32LE(2, 16); // ncmds
+  header.writeUInt32LE(24 + 16, 20); // sizeofcmds
+  const uuidCommand = Buffer.alloc(24);
+  uuidCommand.writeUInt32LE(LC_UUID, 0);
+  uuidCommand.writeUInt32LE(24, 4);
+  uuid.copy(uuidCommand, 8);
+  const sourceVersion = Buffer.alloc(16);
+  sourceVersion.writeUInt32LE(LC_SOURCE_VERSION, 0);
+  sourceVersion.writeUInt32LE(16, 4);
+  sourceVersion.writeBigUInt64LE(0x1122334455667788n, 8);
+  return Buffer.concat([header, uuidCommand, sourceVersion]);
+}
+
+function fatMachO(slices) {
+  const sliceSize = 4096;
+  const tableSize = 8 + slices.length * 20;
+  const buffer = Buffer.alloc(tableSize + slices.length * sliceSize);
+  buffer.writeUInt32BE(0xcafebabe, 0);
+  buffer.writeUInt32BE(slices.length, 4);
+  slices.forEach((slice, index) => {
+    const arch = 8 + index * 20;
+    const offset = tableSize + index * sliceSize;
+    buffer.writeUInt32BE(slice.cpuType, arch);
+    buffer.writeUInt32BE(offset, arch + 8);
+    buffer.writeUInt32BE(slice.data.length, arch + 12);
+    buffer.writeUInt32BE(12, arch + 16); // 2^12 slice alignment
+    slice.data.copy(buffer, offset);
+  });
+  return buffer;
+}
+
+/** Rewrites `buffer` and asserts everything but the UUID payloads survived. */
+function rewrittenLike(original, appId, executableName, uuidFor) {
+  const rewritten = Buffer.from(original);
+  const expected = Buffer.from(original);
+  const locations = machoLcUuidLocations(rewritten);
+  assert.ok(locations.length > 0, 'fixture must carry an LC_UUID');
+  for (const { offset, cpuType } of locations) {
+    const uuid = uuidFor(cpuType);
+    rewritten.write(uuid.replaceAll('-', ''), offset, 'hex');
+    expected.write(uuid.replaceAll('-', ''), offset, 'hex');
+  }
+  rewriteBufferUuids(rewritten, appId, executableName);
+  assert.equal(rewritten.length, original.length, 'file size must not change');
+  assert.deepEqual(rewritten, expected, 'only LC_UUID payloads may move');
+  return { rewritten, locations };
+}
+
+test('uuidv5 follows RFC 4122', () => {
+  // python.org under the DNS namespace is the reference example every
+  // conforming implementation agrees on (verified against python's uuid5).
+  assert.equal(uuidv5(DNS_NAMESPACE, 'python.org'), '886313e1-3b8a-5372-9b90-0c9aee199e5d');
+  assert.match(uuidv5(DNS_NAMESPACE, 'example.org'), /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);

Review Comment:
   Fixed in `465ec366b` — the suite was reformatted (`biome format` clean on both files) and a second commit is on the branch registering nothing new; the head now carries the suite green locally and the formatting gate passes on the exact files.



##########
scripts/macos-lc-uuid.test.mjs:
##########
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import assert from 'node:assert/strict';
+import { mkdir, mkdtemp, readFile, readdir, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { test } from 'node:test';
+import {
+  deterministicExecutableUuid,
+  machoLcUuidLocations,
+  rewriteBufferUuids,
+  rewritePackagedMacosUuids,
+  uuidv5,
+} from './macos-lc-uuid.mjs';
+
+/**
+ * Every packaged Mach-O keeps its byte length and load-command layout; only
+ * the 16 bytes under each LC_UUID move. These fixtures are the smallest
+ * headers that prove that: one LC_UUID and one unrelated load command whose
+ * bytes must survive untouched.
+ */
+const MH_MAGIC_64 = 0xfeedfacf;
+const LC_UUID = 0x1b;
+const LC_SOURCE_VERSION = 0x2a;
+const CPU_TYPE_X86_64 = 0x01000007;
+const CPU_TYPE_ARM64 = 0x0100000c;
+const DNS_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
+
+// The UUID from the issue: every Electron 43.4.1-based app ships this exact
+// Mach-O UUID, which is what makes macOS local-network privacy collide.
+const OLD_UUID = Buffer.from('4c4c447055553144a124518576dd11e3', 'hex');
+
+function thinMachO(cpuType, uuid) {
+  const header = Buffer.alloc(32);
+  header.writeUInt32LE(MH_MAGIC_64, 0);
+  header.writeUInt32LE(cpuType, 4);
+  header.writeUInt32LE(2, 12); // MH_EXECUTE
+  header.writeUInt32LE(2, 16); // ncmds
+  header.writeUInt32LE(24 + 16, 20); // sizeofcmds
+  const uuidCommand = Buffer.alloc(24);
+  uuidCommand.writeUInt32LE(LC_UUID, 0);
+  uuidCommand.writeUInt32LE(24, 4);
+  uuid.copy(uuidCommand, 8);
+  const sourceVersion = Buffer.alloc(16);
+  sourceVersion.writeUInt32LE(LC_SOURCE_VERSION, 0);
+  sourceVersion.writeUInt32LE(16, 4);
+  sourceVersion.writeBigUInt64LE(0x1122334455667788n, 8);
+  return Buffer.concat([header, uuidCommand, sourceVersion]);
+}
+
+function fatMachO(slices) {
+  const sliceSize = 4096;
+  const tableSize = 8 + slices.length * 20;
+  const buffer = Buffer.alloc(tableSize + slices.length * sliceSize);
+  buffer.writeUInt32BE(0xcafebabe, 0);
+  buffer.writeUInt32BE(slices.length, 4);
+  slices.forEach((slice, index) => {
+    const arch = 8 + index * 20;
+    const offset = tableSize + index * sliceSize;
+    buffer.writeUInt32BE(slice.cpuType, arch);
+    buffer.writeUInt32BE(offset, arch + 8);
+    buffer.writeUInt32BE(slice.data.length, arch + 12);
+    buffer.writeUInt32BE(12, arch + 16); // 2^12 slice alignment
+    slice.data.copy(buffer, offset);
+  });
+  return buffer;
+}
+
+/** Rewrites `buffer` and asserts everything but the UUID payloads survived. */
+function rewrittenLike(original, appId, executableName, uuidFor) {
+  const rewritten = Buffer.from(original);
+  const expected = Buffer.from(original);
+  const locations = machoLcUuidLocations(rewritten);
+  assert.ok(locations.length > 0, 'fixture must carry an LC_UUID');
+  for (const { offset, cpuType } of locations) {
+    const uuid = uuidFor(cpuType);
+    rewritten.write(uuid.replaceAll('-', ''), offset, 'hex');

Review Comment:
   Fixed in `465ec366b` — only `expected` gets the target bytes now; `rewritten` stays a verbatim copy of the fixture. Verified by replacing `.copy(buffer, offset)` with a no-op: all of thin/fat/idempotence assertions fail (previously only the afterPack test caught it).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org