Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/artifacts/apple/MachoLoadCommandReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ import { javaClassFile } from "../../../tests/fixtures/javaClassFile.js";
const read = (bytes: Uint8Array) =>
readMachoImage(readerOf(bytes), bytes.length);

it("preserves leading U+FEFF in load-command strings", async () => {
const name = "\ufeff@rpath/libcore.dylib";
const rpath = "\ufeff@loader_path/Frameworks";
const environment = "\ufeffDYLD_FRAMEWORK_PATH=@executable_path";
const facts = await read(
machoImage({
fileType: FILE_TYPE.dylib,
commands: [
dylibCommand(LC.ID_DYLIB, name),
dylibCommand(LC.LOAD_DYLIB, name),
dylibUseCommand(LC.LOAD_DYLIB, name, 0x1),
rpathCommand(rpath),
dyldEnvironmentCommand(environment),
],
}),
);
expect(facts).toMatchObject({
status: "parsed",
slices: [
{
install_name: name,
dependencies: [{ install_name: name }, { install_name: name }],
rpaths: [rpath],
dyld_environment: [environment],
},
],
});
});

// Legacy `LC_VERSION_MIN_*` commands carry no simulator flag: per dyld
// rules Intel images are simulator, ARM images are device (tvOS simulator
// is x86_64 only). A legacy simulator executable must not fail resolution
Expand Down
3 changes: 2 additions & 1 deletion src/artifacts/apple/MachoLoadCommandReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ const commandString = (
`load command ${index} has an unterminated string`,
);
try {
return new TextDecoder("utf-8", { fatal: true }).decode(
// lc_str holds literal filename/environment bytes, not a BOM-marked document.
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
body.subarray(offset, end),
);
} catch {
Expand Down
46 changes: 46 additions & 0 deletions tests/boundary/cli/dylibResolutionCli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,52 @@ const withBrokenHelper = async (app: string): Promise<void> => {
await writeFiles(app, { "Contents/Helpers/broken": broken });
};

cliTest(
"does not turn a leading U+FEFF into an rpath load",
async ({ cli }) => {
const app = await fixtureApp();
const name = "\ufeff@rpath/libcore.dylib";
await writeFiles(app, {
"Contents/MacOS/App": machoImage({
commands: [
buildVersionCommand(1),
rpathCommand("@executable_path/../Frameworks"),
dylibCommand(LC.LOAD_DYLIB, name),
dylibCommand(LC.LOAD_DYLIB, "@rpath/libcore.dylib"),
],
}),
});
const result = await cli.run({
arguments: [
"trace-dylib-resolution",
app,
"--root",
"Contents/MacOS/App",
"--json",
],
environment: ENVIRONMENT,
});
expect(result.exitCode, JSON.stringify(result.json)).toBe(0);
const trace = dylibResolutionResultSchema.parse(
(result.json as { normalized_result: unknown }).normalized_result,
);
expect(
trace.edges.map(({ install_name, resolution }) => ({
install_name,
status: resolution.status,
image: resolution.image,
})),
).toEqual([
{ install_name: name, status: "undetermined", image: null },
{
install_name: "@rpath/libcore.dylib",
status: "resolved",
image: "Contents/Frameworks/libcore.dylib",
},
]);
},
);

describe("trace-dylib-resolution CLI", () => {
cliTest("traces every executable root of an app bundle", async ({ cli }) => {
const app = await fixtureApp();
Expand Down