Target admission accepted a thin Mach-O after reading only its magic and CPU type, so a 12-byte prefix opened as a valid arm64 executable and the first provider query failed as a generic execution failure. ELF headers were likewise accepted after 20 bytes, and a FAT file whose selected slice lies beyond its end was admitted. Require the complete fixed header (Mach-O 28 or 32 bytes, ELF 52 or 64), Mach-O load commands that fit in the file, and a selected FAT slice within the file, checking commitments against the file size rather than the probed prefix. Each refusal names the failed constraint. Fixes #1189 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.3 KiB
TypeScript
55 lines
2.3 KiB
TypeScript
import { chmod, mkdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
|
import { ArtifactProvider } from "../../../../src/artifacts/ArtifactProvider.js";
|
|
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
|
import { thinMach } from "../../../../src/domain/binaryTarget.fixture.js";
|
|
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
|
|
|
describe("artifact directory diagnostics", () => {
|
|
it.skipIf(process.platform === "win32")(
|
|
"preserves the inaccessible member path and errno through provider projection",
|
|
async () => {
|
|
const root = await createTestTempDirectory("rea-directory-eacces-");
|
|
const appPath = join(root, "Denied.app");
|
|
const contentsPath = join(appPath, "Contents");
|
|
const executablePath = join(contentsPath, "MacOS", "Fixture");
|
|
const blockedPath = join(contentsPath, "blocked.txt");
|
|
await mkdir(join(contentsPath, "MacOS"), { recursive: true });
|
|
await writeFile(
|
|
join(contentsPath, "Info.plist"),
|
|
"<plist><dict><key>CFBundleExecutable</key><string>Fixture</string></dict></plist>",
|
|
);
|
|
await writeFile(executablePath, thinMach(0xfeedfacf, 0x0100000c));
|
|
await writeFile(blockedPath, "member contents");
|
|
await chmod(blockedPath, 0);
|
|
try {
|
|
const target = await parseBinaryTarget(appPath);
|
|
if (!target.ok) throw target.error;
|
|
const result = await new ArtifactProvider()
|
|
.createClient(target.value)
|
|
.execute("inventory_artifact", {});
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
code: "artifact_operation_failed",
|
|
details: {
|
|
operation: "inventory_artifact",
|
|
reason: "io",
|
|
},
|
|
});
|
|
const projected = projectAnalysisError(result.error);
|
|
const detail = projected.details?.detail;
|
|
expect(typeof detail).toBe("string");
|
|
expect(detail).toContain("Denied.app/Contents/blocked.txt");
|
|
expect(detail).toContain("EACCES");
|
|
} finally {
|
|
await chmod(blockedPath, 0o600);
|
|
}
|
|
},
|
|
);
|
|
});
|