fix(macho): share lazy dylib linkedit command facts (#12541)

This commit is contained in:
morluto authored and GitHub committed 2026-11-19 22:07:40 +00:00
1 parent 9d0502bc51
commit 3f0f993233
4 files changed
+46 -9

No files matched your search

+7 -4
View File
@@ -794,14 +794,17 @@ const decodeLazyLoadDylibInfoCommand = (
body: Uint8Array,
index: number,
): LazyLoadDylibInfoCommand => {
if (body.byteLength < 16)
const data = readMachoLinkeditDataCommand(
LC.LAZY_LOAD_DYLIB_INFO,
body,
true,
);
if (data === null)
throw machoIssue(
"malformed",
`load command ${index} is too short for LC_LAZY_LOAD_DYLIB_INFO`,
);
const reader = machoWordReader(body, true);
const dataOffset = reader.u32(8);
const dataSize = reader.u32(12);
const { dataOffset, dataSize } = data;
if (dataSize < LAZY_INFO_HEADER_BYTES)
throw machoIssue(
"malformed",
+1
View File
@@ -254,6 +254,7 @@ const FIXED_WORD_FIELDS: ReadonlyMap<number, readonly string[]> = new Map([
[LC.ATOM_INFO, ["dataoff", "datasize"]],
[LC.FUNCTION_VARIANTS, ["dataoff", "datasize"]],
[LC.FUNCTION_VARIANT_FIXUPS, ["dataoff", "datasize"]],
[LC.LAZY_LOAD_DYLIB_INFO, ["dataoff", "datasize"]],
]);
/** Names of a command's fixed uint32 fields, or undefined for other layouts. */
+34 -1
View File
@@ -3,6 +3,7 @@ import { projectMachoBinary } from "./MachoBinaryProjection.js";
import type { MachoCommandNames } from "../domain/apple/machoCommandNames.js";
import { readMachoCommandNames } from "../domain/apple/machoCommandNames.js";
import {
lazyLoadDylibInfoCommand,
machoImage,
readerOf,
segmentCommand,
@@ -392,6 +393,30 @@ it("distinguishes exact fixed command extents from unmodeled trailing bytes", as
]);
});
it("reports lazy dylib linkedit fields and retains a digest when the command has a tail", async () => {
const exact = lazyLoadDylibInfoCommand(0x340, 56);
const extended = Buffer.concat([exact, Buffer.alloc(8, 0xa5)]);
extended.writeUInt32LE(extended.length, 4);
const image = machoImage({ commands: [exact, extended] });
const result = projectMachoBinary(
await readMachoCommandNames(readerOf(image), image.length, 1024, 8),
);
expect(result.commands[0]?.fields).toMatchObject({
dataoff: 0x340,
datasize: 56,
});
expect(result.commands[0]?.fields).not.toHaveProperty("command_sha256");
expect(result.commands[1]?.fields).toMatchObject({
dataoff: 0x340,
datasize: 56,
command_sha256: expect.stringMatching(/^[a-f0-9]{64}$/u),
});
expect(result.dependencyLimitations).toEqual([
"The linkedit dependency payload is not decoded.",
]);
});
it("preserves leading UTF-8 BOM characters in names and dependency paths", () => {
const marker = "\uFEFF";
const commands = multilineBinary.commands.map((row) => ({
@@ -449,7 +474,15 @@ it("reports undecoded lazy dependency payloads and unsafe entrypoint offsets", (
flags: 0,
},
commands: [
{ index: 0, command: 0x3a, offset: 0, size: 16, rawSha256: null },
{
index: 0,
command: 0x3a,
offset: 0,
size: 16,
fixedFields: { dataoff: 0x340, datasize: 56 },
fullyDecoded: true,
rawSha256: null,
},
{
index: 1,
command: 0x80000028,
+4 -4
View File
@@ -515,13 +515,13 @@ export const projectMachoBinary = (
}
if (kind === "LC_THREAD" || kind === "LC_UNIXTHREAD")
entrypointLimitations.add("Thread-state entrypoints are not decoded.");
if (kind === "LC_LAZY_LOAD_DYLIB_INFO")
dependencyLimitations.add(
"The linkedit dependency payload is not decoded.",
);
if (kind.startsWith("LC_VERSION_MIN_") || kind === "LC_BUILD_VERSION")
buildLimitations.add(`The ${kind} payload is not decoded.`);
}
if (kind === "LC_LAZY_LOAD_DYLIB_INFO")
dependencyLimitations.add(
"The linkedit dependency payload is not decoded.",
);
commands.push({ index: row.index, kind, fields });
}
return {