Merge pull request #1196 from morluto/fix/target-truncated-headers

fix(native): refuse truncated executable headers at target admission
This commit is contained in:
Kaoru0822
2026-10-08 21:13:15 -07:00
committed by GitHub
7 changed files with 140 additions and 21 deletions
@@ -325,6 +325,32 @@ describe("binary target I/O: explicit kinds and executable headers", () => {
architecture: "x86_64",
});
});
it("refuses a truncated Mach-O header before any provider sees it", async () => {
const directory = await createTestTempDirectory("rea-target-");
const path = join(directory, "truncated");
await writeFile(path, thinMach(0xcffaedfe, 0x0100000c).subarray(0, 12));
const result = await parseBinaryTarget(path, directory, "arm64");
expect(result.ok).toBe(false);
expect(result.ok ? undefined : result.error).toMatchObject({
path,
reason:
"truncated Mach-O header: a 64-bit header needs 32 bytes; the file has 12",
});
});
it("checks Mach-O load commands against the whole file beyond the probe", async () => {
const directory = await createTestTempDirectory("rea-target-");
const path = join(directory, "large-commands");
const header = thinMach(0xcffaedfe, 0x0100000c);
header.writeUInt32LE(8192, 20);
await writeFile(path, Buffer.concat([header, Buffer.alloc(8192)]));
const result = await parseBinaryTarget(path, directory, "arm64");
expect(result.ok && result.value).toMatchObject({
format: "mach-o",
architecture: "arm64",
});
});
});
describe("app executable filename fidelity", () => {
@@ -6,6 +6,7 @@ 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", () => {
@@ -22,10 +23,7 @@ describe("artifact directory diagnostics", () => {
join(contentsPath, "Info.plist"),
"<plist><dict><key>CFBundleExecutable</key><string>Fixture</string></dict></plist>",
);
const machHeader = Buffer.alloc(8);
machHeader.writeUInt32BE(0xfeedfacf, 0);
machHeader.writeUInt32BE(0x0100000c, 4);
await writeFile(executablePath, machHeader);
await writeFile(executablePath, thinMach(0xfeedfacf, 0x0100000c));
await writeFile(blockedPath, "member contents");
await chmod(blockedPath, 0);
try {
@@ -18,6 +18,7 @@ import {
import { projectAppleApplicationEvidence } from "../../../src/application/apple/AppleApplicationService.js";
import { runProviderAnalysis } from "../../../src/composition/directAnalysis.js";
import { thinMach } from "../../../src/domain/binaryTarget.fixture.js";
import { appleApplicationProjectionResultSchema } from "../../../src/domain/apple/appleApplication.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
@@ -188,7 +189,8 @@ describe("macOS application projection", () => {
it("projects a macOS .app directory inventory with nested bundle roles", async () => {
const root = await createTestTempDirectory("rea-apple-macos-");
const app = join(root, "Fixture.app");
const machO = Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]);
// A complete thin arm64 header, as target admission requires.
const machO = thinMach(0xcffaedfe, 0x0100000c);
const files: [string, string | Uint8Array][] = [
[
"Contents/Info.plist",