From d8554c1c84a1ffb84c0586283370a471a5b060ab Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:36:02 +0000 Subject: [PATCH] fix(bun): append segment claims without call arguments Supersedes #10342 Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --- src/artifacts/bun/BunModuleGraphLayout.ts | 17 ++++++------ tests/acceptance/bunStandaloneCli.test.ts | 33 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/artifacts/bun/BunModuleGraphLayout.ts b/src/artifacts/bun/BunModuleGraphLayout.ts index a6066eedb2..6fe65fb6ab 100644 --- a/src/artifacts/bun/BunModuleGraphLayout.ts +++ b/src/artifacts/bun/BunModuleGraphLayout.ts @@ -513,15 +513,14 @@ const machOClaims = async ( if (!read.ok) break; const { command: cmd, offset, size } = read.value; if (cmd === LC_SEGMENT_64 || cmd === LC_SEGMENT) - claims.push( - ...segmentClaims( - commands.subarray(offset, offset + size), - littleEndian, - cmd === LC_SEGMENT_64, - imageOffset, - Math.min(fileSize, imageOffset + imageLimit), - ), - ); + for (const claim of segmentClaims( + commands.subarray(offset, offset + size), + littleEndian, + cmd === LC_SEGMENT_64, + imageOffset, + Math.min(fileSize, imageOffset + imageLimit), + )) + claims.push(claim); } return claims; }; diff --git a/tests/acceptance/bunStandaloneCli.test.ts b/tests/acceptance/bunStandaloneCli.test.ts index 763b815043..78977a801f 100644 --- a/tests/acceptance/bunStandaloneCli.test.ts +++ b/tests/acceptance/bunStandaloneCli.test.ts @@ -6,8 +6,12 @@ import { cliTest } from "../support/cli/cliFixture.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { bunModuleGraphPayload, + bunPrefixedPayload, + machoBunSections, elfAppendedBunPayload, } from "../../src/artifacts/bun/BunStandalone.fixture.js"; +import { DEFAULT_BUN_READER_LIMITS } from "../../src/domain/artifactReaderLimits.js"; +import { CPU_ARM64, universalMacho } from "../fixtures/universalMacho.js"; import { parseEvidence } from "../../src/domain/evidence.js"; import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js"; import { @@ -15,6 +19,35 @@ import { artifactExtractionResultSchema, } from "../../src/domain/artifactGraph.js"; +cliTest( + "reports large Bun section ambiguity through the compiled CLI", + async ({ cli }) => { + const root = await createTestTempDirectory("rea-bun-many-sections-"); + const source = join(root, "app"); + const graph = bunPrefixedPayload(bunModuleGraphPayload({ modules: [{}] })); + const thin = machoBunSections(Array.from({ length: 200_000 }, () => graph)); + expect(thin.readUInt32LE(20)).toBeLessThanOrEqual( + DEFAULT_BUN_READER_LIMITS.recognition_load_command_bytes, + ); + const fat = universalMacho([ + { bytes: thin, cpuType: CPU_ARM64, cpuSubtype: 0 }, + ]); + await writeFile(source, fat.bytes); + const inspected = await cli.run({ + arguments: ["inspect-artifact", source, "--json"], + }); + expect(inspected.exitCode, inspected.stdout + inspected.stderr).toBe(1); + expect(inspected.json).toMatchObject({ + code: "artifact_operation_failed", + category: "unavailable", + details: { + reason: "unavailable", + detail: expect.stringContaining("multiple embedded graphs"), + }, + }); + }, +); + cliTest( "inventories and extracts Bun source from its carrier", async ({ cli }) => {