Move ELF, PE and Mach-O container parsing into a shared native owner. Go alone selects and validates Go build-info sections, so unrelated malformed Go metadata no longer blocks Rust dependency or IL2CPP inspection. Remove the superseded Go-specific container representation and migrate all consumers. Adapted from draft PR #5510 without asserting human PR readiness. Validation: 51 compiled CLI/MCP acceptance tests across Rust, Go and IL2CPP; 186 shared-reader tests; full check:ci passed. Three public synthetic-file probes reproduce the baseline Rust refusal and validate the fixed SDK-advertised MCP output, artifact digests and unchanged bytes. The exact zero-address nonallocated ELF case now succeeds for Rust while Go still reports invalid_format. No target execution or real compiler-artifact qualification was performed; no performance improvement is claimed. Closes #3398
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { mappedFileOffset } from "../../../src/native/metadata/BinaryContainer.js";
|
|
|
|
const selected = { address: 100n, offset: 16, size: 64 };
|
|
|
|
it.each([
|
|
{ address: 132n, offset: 4, size: 4 },
|
|
{ address: 112n, offset: 4, size: 12 },
|
|
])(
|
|
"rejects a contradictory alias overlapping only part of the selected bytes",
|
|
(alias) => {
|
|
expect(() => mappedFileOffset([selected, alias], 120n, 24)).toThrowError(
|
|
/ambiguous/i,
|
|
);
|
|
},
|
|
);
|
|
|
|
it("accepts overlapping aliases that identify exactly the same file bytes", () => {
|
|
expect(
|
|
mappedFileOffset(
|
|
[selected, { address: 132n, offset: 48, size: 4 }],
|
|
120n,
|
|
24,
|
|
),
|
|
).toBe(36);
|
|
});
|
|
|
|
it("does not confuse adjacent mappings with overlapping byte spans", () => {
|
|
const adjacent = { address: 164n, offset: 80, size: 32 };
|
|
expect(mappedFileOffset([selected, adjacent], 140n, 24)).toBe(56);
|
|
expect(mappedFileOffset([selected, adjacent], 164n, 0)).toBe(80);
|
|
});
|
|
|
|
it.each([
|
|
{ address: 132n, size: 4n },
|
|
{ address: 112n, size: 12n },
|
|
])(
|
|
"rejects zero-fill aliases overlapping part of file-backed bytes",
|
|
(zeroFill) => {
|
|
expect(() =>
|
|
mappedFileOffset([selected], 120n, 24, [zeroFill]),
|
|
).toThrowError(/ambiguous/i);
|
|
},
|
|
);
|
|
|
|
it("keeps adjacent zero-filled memory outside the selected file span", () => {
|
|
expect(
|
|
mappedFileOffset([selected], 140n, 24, [{ address: 164n, size: 32n }]),
|
|
).toBe(56);
|
|
});
|