fix(go): accept file-backed unmapped Mach-O debug segments

Validate unmapped segment file ranges without adding virtual mappings or fallback metadata addresses. Keep mapped-segment bounds and reject build-info sections declared in unmapped segments.

Validation: real unstripped Go 1.26.5 Darwin arm64 and amd64 artifacts passed CLI/MCP oracle, Evidence, source-range and unchanged-byte checks. Retained malformed-input regressions; removed the weaker synthetic acceptance test. Full cross-platform verifier not run. Fixes #2167.
This commit is contained in:
morluto
2026-10-13 03:47:45 +08:00
parent c9fed50691
commit 7fb097d72c
3 changed files with 102 additions and 20 deletions
+19 -9
View File
@@ -115,16 +115,25 @@ try {
],
{ GOOS: os, GOARCH: arch },
);
await verify(path, target, oracle);
await verify(path, target, oracle, null, "stripped");
if (os === "linux" && arch === "amd64") {
const sectionless = join(root.path, "linux-amd64-sectionless");
const bytes = Buffer.from(await readFile(path));
bytes.fill(0, 40, 48); // ELF64 e_shoff.
bytes.fill(0, 58, 64); // e_shentsize, e_shnum and e_shstrndx.
await writeFile(sectionless, bytes);
await verify(sectionless, target, oracle);
await verify(sectionless, target, oracle, null, "sectionless");
}
}
for (const target of targets.filter(([os]) => os === "darwin")) {
const [os, arch] = target;
const path = join(root.path, `${os}-${arch}-unstripped`);
await go(["build", "-trimpath", "-buildvcs=false", "-o", path, "."], {
GOOS: os,
GOARCH: arch,
});
await verify(path, target, oracle, null, "unstripped");
}
if (process.platform === "win32")
omittedCoverage.push(
"Compiler-produced non-UTF-8 argv strings were not verified on Windows; Windows argv cannot preserve arbitrary byte arguments.",
@@ -317,7 +326,13 @@ async function inspect(mode, path) {
return { evidence, report };
}
async function verify(path, target, oracle, byteExpected = null) {
async function verify(
path,
target,
oracle,
byteExpected = null,
fileKind = "stripped",
) {
const bytes = await readFile(path);
const expected =
byteExpected ??
@@ -387,12 +402,7 @@ async function verify(path, target, oracle, byteExpected = null) {
);
verified.push({
target: `${target[0]}/${target[1]}`,
file:
byteExpected === null
? path.endsWith("sectionless")
? "sectionless"
: "stripped"
: "byte-valued-strings",
file: byteExpected === null ? fileKind : "byte-valued-strings",
go_version: expected.GoVersion,
...(byteExpected === null
? {}