fix(native): reject ambiguous otool load-command framing
Validate Mach command counts, byte totals, scalar uniqueness, section counts, and build-tool counts before claiming exhaustive evidence. Preserve raw output in typed parsing failures and distinguish dylib commands from the dynamic loader. Correct inconsistent handcrafted fixtures and label their provenance. Validation: 38 native tests, combined checks, and temporary-directory hygiene. Multiline dylib-name ambiguity was reproduced with the host Apple otool; regression workflows use captured output and injected command runners.
This commit is contained in:
@@ -108,7 +108,37 @@ export const inspectNativeMacho = async (
|
||||
else if (optional.error._tag === "AnalysisCapabilityUnavailableError")
|
||||
limitations.push(VTOOL_UNAVAILABLE_LIMITATION);
|
||||
else return err(optional.error);
|
||||
const normalized = normalizeMacho(captures, context.invocation, limitations);
|
||||
const otool = captures.find(({ tool }) => tool === "otool");
|
||||
if (otool === undefined) throw new TypeError("Missing otool capture");
|
||||
let load: ReturnType<typeof parseOtoolLoadCommands>;
|
||||
try {
|
||||
load = parseOtoolLoadCommands(sliceOutput(otool));
|
||||
} catch (cause: unknown) {
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
"inspect_macho",
|
||||
"Malformed otool load-command output",
|
||||
{
|
||||
cause,
|
||||
capturedOutput: {
|
||||
stdout: otool.stdout,
|
||||
stderr: otool.stderr,
|
||||
truncated: false,
|
||||
stdout_bytes: otool.stdoutBytes,
|
||||
stderr_bytes: otool.stderrBytes,
|
||||
exit_code: otool.exitCode,
|
||||
signal: otool.signal,
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
const normalized = normalizeMacho(
|
||||
captures,
|
||||
context.invocation,
|
||||
limitations,
|
||||
load,
|
||||
);
|
||||
const segmentOffset = segmentContainerOffset(
|
||||
normalized,
|
||||
selectedArchitecture,
|
||||
@@ -135,10 +165,10 @@ const normalizeMacho = (
|
||||
captures: readonly NativeCommandCapture[],
|
||||
toInvocation: (capture: NativeCommandCapture) => NativeCommandInvocation,
|
||||
additionalLimitations: readonly string[],
|
||||
load: ReturnType<typeof parseOtoolLoadCommands>,
|
||||
) => {
|
||||
const byTool = captureLookup(captures);
|
||||
const architectures = parseLipoArchitectures(byTool("lipo").stdout);
|
||||
const load = parseOtoolLoadCommands(sliceOutput(byTool("otool")));
|
||||
const imports = parseDyldSymbols(
|
||||
sliceOutput(byTool("dyld_info", 0)),
|
||||
"imports",
|
||||
|
||||
Reference in New Issue
Block a user