mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
fix(native): keep Objective-C class import coverage partial when candidate completeness is unstated (#11128)
This commit is contained in:
1 parent
28d28b0578
commit
682a57a987
10 files changed
+69
-13
No files matched your search
@@ -61,6 +61,14 @@ const check = (label, selected, pattern, allow = []) => {
|
||||
);
|
||||
};
|
||||
|
||||
// Completeness is a claim its producer establishes from examined input. A
|
||||
// fallback or default of `true` turns an unstated claim into a complete one.
|
||||
check(
|
||||
"completeness defaulted to true (leave it unknown or require the producer to state it)",
|
||||
files,
|
||||
/\b(?:complete|exhaustive|\w+Complete|\w+Exhaustive|\w+_complete|\w+_exhaustive)\w*\s*(?:\?\?\s*true\b|(?::\s*boolean\s*)?=\s*true\s*[,)])/u,
|
||||
);
|
||||
|
||||
// Prerequisite inspection lifetime is an application contract shared by adapters.
|
||||
check(
|
||||
"provider-owned inspection lifetime (use src/application/ProviderInspectionScope)",
|
||||
|
||||
@@ -61,7 +61,7 @@ export interface ElectronIpcContext {
|
||||
export const createElectronIpcContext = (
|
||||
analysis: JavaScriptArtifactAnalysis,
|
||||
applicationOwner: (file: JavaScriptArtifactFile) => string | null,
|
||||
coverageComplete = true,
|
||||
coverageComplete: boolean,
|
||||
): ElectronIpcContext => {
|
||||
const records = collectElectronIpcRecords(analysis);
|
||||
const owners = new Map(
|
||||
|
||||
@@ -464,7 +464,7 @@ it("attaches sender validation to the innermost handler after a long minified li
|
||||
addJavaScriptArtifactFiles(context);
|
||||
addElectronIpcBoundaries(
|
||||
context,
|
||||
createElectronIpcContext(analysis, () => "app"),
|
||||
createElectronIpcContext(analysis, () => "app", true),
|
||||
);
|
||||
const handlers = context.accumulator
|
||||
.nodes()
|
||||
|
||||
@@ -44,8 +44,12 @@ export const inspectNativeDispatch = async (
|
||||
? {}
|
||||
: {
|
||||
objc_class_import_addresses: [...objcClassImportAddresses],
|
||||
objc_class_import_addresses_complete:
|
||||
objcClassImportAddressesComplete ?? true,
|
||||
...(objcClassImportAddressesComplete === undefined
|
||||
? {}
|
||||
: {
|
||||
objc_class_import_addresses_complete:
|
||||
objcClassImportAddressesComplete,
|
||||
}),
|
||||
}),
|
||||
};
|
||||
const binaryMetadata = await analysis.execute(
|
||||
|
||||
@@ -466,7 +466,7 @@ export const nativeDispatchMetadataInputSchema = z.strictObject({
|
||||
objc_class_import_addresses_complete: z
|
||||
.boolean()
|
||||
.describe(
|
||||
"Whether the candidate addresses include every selected class-label row; false keeps binding coverage partial when the existing record budget truncates the scan.",
|
||||
"Whether the candidate addresses include every selected class-label row. false keeps binding coverage partial when the existing record budget truncates the scan; omitted is unknown and also keeps it partial.",
|
||||
)
|
||||
.optional(),
|
||||
max_input_bytes: z
|
||||
|
||||
@@ -468,6 +468,7 @@ describe("Imported class symbol byte identities", () => {
|
||||
provenance,
|
||||
"arm64",
|
||||
["0x100000b00"],
|
||||
true,
|
||||
);
|
||||
expect(result.swift_conformances).toMatchObject([
|
||||
{
|
||||
@@ -500,6 +501,25 @@ describe("Imported class symbol byte identities", () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe("Imported class symbol candidate completeness", () => {
|
||||
it("keeps binding coverage partial when the caller does not state the candidates are complete", () => {
|
||||
const result = decodeAppleDispatchMetadata(
|
||||
swiftExternalSwiftBindingImage("objc-class"),
|
||||
100,
|
||||
provenance,
|
||||
"arm64",
|
||||
["0x100000b00"],
|
||||
);
|
||||
expect(result.objc_class_import_bindings).toEqual([
|
||||
expect.objectContaining({ symbol: "_OBJC_CLASS_$_NSObject" }),
|
||||
]);
|
||||
expect(result.objc_class_import_binding_coverage).toMatchObject({
|
||||
status: "partial",
|
||||
reason: expect.stringContaining("objc_class_import_addresses_complete"),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Imported library byte identities", () => {
|
||||
it.each(["invalid bytes", "literal replacement character"] as const)(
|
||||
"keeps Swift and Objective-C library identity distinct for %s",
|
||||
@@ -518,6 +538,7 @@ describe("Imported library byte identities", () => {
|
||||
provenance,
|
||||
"arm64",
|
||||
["0x100000b00"],
|
||||
true,
|
||||
);
|
||||
expect(result.swift_conformances).toMatchObject([
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ export function* decodeAppleDispatchMetadataSteps(
|
||||
provenance: { path: string; sha256: string },
|
||||
architecture = "arm64",
|
||||
objcClassImportAddresses?: readonly string[],
|
||||
objcClassImportAddressesComplete = true,
|
||||
objcClassImportAddressesComplete?: boolean,
|
||||
admittedSlice?: AdmittedMachoSlice,
|
||||
): Generator<void, ObjcSwiftMetadata, void> {
|
||||
const selected = selectMachoSlice(bytes, {
|
||||
@@ -362,6 +362,7 @@ const inputBudgetExceeded = (
|
||||
export interface AppleDispatchMetadataOptions {
|
||||
readonly signal?: AbortSignal | undefined;
|
||||
readonly objcClassImportAddresses?: readonly string[] | undefined;
|
||||
/** Whether the addresses cover every class-label row; omitted is unknown. */
|
||||
readonly objcClassImportAddressesComplete?: boolean | undefined;
|
||||
/** Caller-selected input budget; the default applies when omitted. */
|
||||
readonly maxInputBytes?: number | undefined;
|
||||
@@ -421,7 +422,7 @@ export const inspectAppleDispatchMetadata = async (
|
||||
{ path: target.path, sha256: digest },
|
||||
target.architecture,
|
||||
options.objcClassImportAddresses,
|
||||
options.objcClassImportAddressesComplete ?? true,
|
||||
options.objcClassImportAddressesComplete,
|
||||
target.format === "mach-o-universal" ? target.universalSlice : undefined,
|
||||
);
|
||||
let next = steps.next();
|
||||
|
||||
@@ -225,3 +225,17 @@ describe("Objective-C import binding address inspection", () => {
|
||||
).toMatchObject({ status: "not_requested", reason: null, examined: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("Objective-C import binding candidate completeness", () => {
|
||||
it("keeps coverage partial when the candidates' completeness was not stated", () => {
|
||||
for (const addresses of [["0x1000", "0x1008"], []])
|
||||
expect(
|
||||
inspectObjcClassImportBindings(
|
||||
createInput({ addresses, addressesComplete: undefined }),
|
||||
).coverage,
|
||||
).toMatchObject({
|
||||
status: "partial",
|
||||
reason: expect.stringContaining("did not state"),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -18,14 +18,18 @@ export const inspectObjcClassImportBindings = (input: {
|
||||
readonly layout: MachoLayout;
|
||||
readonly fixups: PointerFixups;
|
||||
readonly addresses: readonly string[] | undefined;
|
||||
readonly addressesComplete: boolean;
|
||||
/** Whether `addresses` covers every class-label row; undefined is unknown. */
|
||||
readonly addressesComplete: boolean | undefined;
|
||||
readonly maxRecords: number;
|
||||
}): ObjcClassImportBindingScan => {
|
||||
const { bytes, layout, fixups, addresses, addressesComplete, maxRecords } =
|
||||
input;
|
||||
// An explicitly truncated candidate scan keeps its limitation even when no
|
||||
// candidate was retained.
|
||||
if (addresses === undefined || (addresses.length === 0 && addressesComplete))
|
||||
// A candidate scan that is truncated, or whose completeness was not stated,
|
||||
// keeps its limitation even when no candidate was retained.
|
||||
if (
|
||||
addresses === undefined ||
|
||||
(addresses.length === 0 && addressesComplete === true)
|
||||
)
|
||||
return {
|
||||
bindings: [],
|
||||
coverage: {
|
||||
@@ -47,10 +51,14 @@ export const inspectObjcClassImportBindings = (input: {
|
||||
};
|
||||
|
||||
const reasons = new Set<string>();
|
||||
if (!addressesComplete)
|
||||
if (addressesComplete === false)
|
||||
reasons.add(
|
||||
"Candidate address scan reached the existing max_records limit",
|
||||
);
|
||||
if (addressesComplete === undefined)
|
||||
reasons.add(
|
||||
"The caller did not state whether the candidate addresses include every class-label row (objc_class_import_addresses_complete)",
|
||||
);
|
||||
for (const failure of fixups.failures) reasons.add(failure);
|
||||
|
||||
const bindings: MachoImportBinding[] = [];
|
||||
|
||||
@@ -343,7 +343,7 @@ class NativeMacOSClient implements AnalysisClient {
|
||||
signal: options?.signal,
|
||||
objcClassImportAddresses: input.data.objc_class_import_addresses,
|
||||
objcClassImportAddressesComplete:
|
||||
input.data.objc_class_import_addresses_complete ?? true,
|
||||
input.data.objc_class_import_addresses_complete,
|
||||
maxInputBytes: input.data.max_input_bytes,
|
||||
},
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user