Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(apple): own IPS join admission budgets and completed facts
  • Loading branch information
morluto committed Nov 9, 2026
commit 824c64ae1958f040254028eae098efd71d05bc47
15 changes: 15 additions & 0 deletions docs/apple-ips.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,18 @@ rea inspect-apple-ips /absolute/path/to/report.ips --max-integer-text-bytes 1677
`max_join_bytes` (`--max-join-bytes`) independently bounds the join artifact
read, defaulting to 64 MiB. This workflow does not execute a target, launch
atos, or search for dSYMs.


## Join admission and failures

The join uses the shared Mach-O container, slice, command-table and segment
readers. Slice extents and `sizeofcmds` bound every identity observation; duplicate
UUIDs or malformed commands cannot select the first plausible value. Unreadable
join results retain the successfully read artifact's path, SHA-256 and byte count.

The integer-text allowance spans the report and join, including repeated integer
facts and derived static addresses. Reservation precedes derived address
expansion. If a selected join read, interpretation or allowance fails, the error
retains the completed IPS report. Join read limits and recovery use
`max_join_bytes`, even when the report and join paths are identical. Cancellation
retains the caller's reason independently of those completed facts.
4 changes: 3 additions & 1 deletion src/artifacts/StableArtifactFailure.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { StableArtifactSnapshot } from "./readStableArtifact.js";
import type { AnalysisError } from "../domain/analysisErrorBase.js";
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
Expand Down Expand Up @@ -52,8 +53,9 @@ export const projectStableArtifactFailure = (
path: string,
providerId: string,
operation: string,
snapshot?: StableArtifactSnapshot,
): AnalysisError => {
const observation = completedStableArtifactObservation(cause, path);
const observation = completedStableArtifactObservation(cause, path, snapshot);
if (observation !== undefined) primary.retainPartialObservation(observation);
const cleanup = artifactCleanupFailure(cause, providerId, operation);
if (cleanup === undefined) return primary;
Expand Down
8 changes: 6 additions & 2 deletions src/artifacts/StableArtifactObservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import {
fileSnapshotPartialObservationSchema,
type FileSnapshotPartialObservation,
} from "../domain/fileSnapshotObservation.js";
import { completedStableArtifact } from "./readStableArtifact.js";
import {
type StableArtifactSnapshot,
completedStableArtifact,
} from "./readStableArtifact.js";

/** Completed file identity survives finalization; it does not establish decoded content. */
export const completedStableArtifactObservation = (
cause: unknown,
path: string,
completedSnapshot?: StableArtifactSnapshot,
): FileSnapshotPartialObservation | undefined => {
const snapshot = completedStableArtifact(cause);
const snapshot = completedSnapshot ?? completedStableArtifact(cause);
return snapshot === undefined
? undefined
: fileSnapshotPartialObservationSchema.parse({
Expand Down
2 changes: 2 additions & 0 deletions src/domain/analysisErrorBase.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AppleIps } from "./native/appleIps.js";
import type { PlaywrightTrace } from "./playwrightTrace/playwrightTrace.js";
import type { GraphqlContract } from "./apiContract/graphqlContract.js";
import type { SavedAnalysisSnapshotPartialObservation } from "./savedAnalysisSnapshot.js";
Expand Down Expand Up @@ -506,6 +507,7 @@ export type AnalysisPartialObservation =
| Evidence
| BinaryLayout
| RecordedCrash
| AppleIps
| RecordedCrashPartialObservation
| AndroidPartialObservation
| FirmwarePartialObservation
Expand Down
18 changes: 18 additions & 0 deletions src/domain/native/appleIps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ const joinSchema = z.discriminatedUnion("status", [
z.strictObject({
status: z.literal("unreadable"),
path: z.string().min(1),
sha256: digestSchema,
bytes: uint,
reason: z.string().min(1),
}),
]);
Expand Down Expand Up @@ -415,5 +417,21 @@ export const appleIpsReportIntegerTextBytes = (report: AppleIps): number => {
}
for (const mismatch of report.coverage.type_mismatches)
bytes += 2 * (mismatch.recorded_integer?.length ?? 0);
if (report.join?.status === "selected") {
for (const slice of report.join.slices)
bytes +=
2 *
(slice.offset.length +
slice.cpu_type.length +
slice.cpu_subtype.length) +
appleIpsIntegerTextBytes(slice.text_vmaddr);
for (const match of report.join.image_matches)
bytes +=
2 * match.slice_offset.length +
appleIpsIntegerTextBytes(match.text_vmaddr) +
appleIpsIntegerTextBytes(match.runtime_base);
for (const frame of report.join.frames)
bytes += appleIpsIntegerTextBytes(frame.static_address);
}
return bytes;
};
36 changes: 36 additions & 0 deletions src/native/apple/AppleIpsFieldReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,42 @@ export class FieldReader {
return this.#retain(value, value.toString(), reserved);
}

/** Charge each serialized appearance of a borrowed integer, without reinterpreting it. */
retainIntegerReference(
value: RecordedInteger | null,
): RecordedInteger | null {
const bytes = appleIpsIntegerTextBytes(value);
if (bytes > this.maximumIntegerTextBytes - this.#integerTextBytes)
throw new AppleIpsResourceFailure(
"integer_text",
this.maximumIntegerTextBytes,
"Repeated join integer exceeds the retained text allowance",
);
this.#integerTextBytes += bytes;
return value;
}

recordedUnsigned64(value: bigint): RecordedInteger {
const reserved = this.#reserve(20, true);
const result = this.#retain(value, value.toString(), reserved);
this.#integers.set(result, value);
return result;
}

decimalText64(value: bigint): string {
const reserved = this.#reserve(20, false);
const result = value.toString();
this.#integerTextBytes -= reserved - result.length * 2;
return result;
}

hexText32(value: number): string {
const reserved = this.#reserve(10, false);
const result = `0x${value.toString(16)}`;
this.#integerTextBytes -= reserved - result.length * 2;
return result;
}

mismatch(path: string, expected: string, value: LosslessJson | undefined) {
this.mismatches.push({ path, expected, observed: observedType(value) });
}
Expand Down
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.