Files
reverse-engineering-anything/src/application/native/NativeMatchingAdmission.ts
T
ae09e3fe70 fix(native): recover macOS command deadlines (#6059)
* fix(native): recover macOS command deadlines

Promote native_command_timeout_ms (default 60000), native_ui_deadline_ms
(default 180000), and pwntools_timeout_ms (default 30000) as validated
per-call settings. Keep cpuSeconds, byte allowances, LLDB grace, and plist
probes fixed, and say those caps have no runtime override.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* fix(native): report the deadline that actually expired

Pass the selected native command timeout through xcrun resolution, thread
the pwntools deadline into pwndbg failures, and state the selected UI
deadline apart from the fixed wait-step cap. SIGXFSZ and EFBIG recovery
names the file-size allowance.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* fix(native): honor the selected deadline on helper stages

The UI helper compile and capture subprocesses used fixed 60s and 30s
exec timeouts, so a longer native_ui_deadline_ms still failed as a generic
provider error. Preparation timeouts reported the 60000 ms default instead
of the selected native_command_timeout_ms.

Memory resource-constraint recovery names memory again, and the Darwin
plist CLI expectation matches the byte-counted input allowance.

Co-authored-by: morluto <morluto@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <morluto@users.noreply.github.com>
2026-10-22 02:59:27 +08:00

67 lines
2.3 KiB
TypeScript

import { setImmediate } from "node:timers/promises";
import { AnalysisResourceConstraintError } from "../../domain/analysisErrorCore.js";
import { fixedNativeAllowance } from "../../domain/native/nativeDeadlines.js";
const NATIVE_MATCHING_REPRESENTATION_BYTES = 96 * 1024 * 1024;
/** Budget the actual selected observations, before cloning or index allocation. */
export class NativeMatchingAdmission {
#remaining = NATIVE_MATCHING_REPRESENTATION_BYTES;
#work = 0;
readonly #seen = new WeakSet<object>();
constructor(
readonly operation: string,
readonly signal?: AbortSignal,
) {}
readonly checkpoint = async (bytes = 0): Promise<void> => {
this.#remaining -= bytes;
if (this.#remaining < 0)
throw new AnalysisResourceConstraintError(
this.operation,
"capacity",
`Native function matching exceeds its ${String(NATIVE_MATCHING_REPRESENTATION_BYTES)}-byte (96 MiB) representation allowance. This release has no runtime override.`,
{ maximum_bytes: NATIVE_MATCHING_REPRESENTATION_BYTES },
fixedNativeAllowance(
"The native function-matching representation allowance",
"bytes",
`${String(NATIVE_MATCHING_REPRESENTATION_BYTES)} bytes`,
),
);
this.signal?.throwIfAborted();
if (++this.#work % 256 === 0)
await setImmediate(
undefined,
this.signal === undefined ? {} : { signal: this.signal },
);
};
async admit(root: unknown): Promise<void> {
const pending: Iterator<unknown>[] = [[root][Symbol.iterator]()];
while (pending.length) {
const next = pending[pending.length - 1]!.next();
if (next.done) {
pending.pop();
continue;
}
const value = next.value;
if (typeof value === "object" && value !== null) {
if (this.#seen.has(value)) continue;
this.#seen.add(value);
await this.checkpoint(128);
// Iterator traversal avoids a second width-sized array of child values.
pending.push(
(function* () {
for (const key in value)
if (Object.hasOwn(value, key)) {
yield key;
yield (value as Record<string, unknown>)[key];
}
})(),
);
} else
await this.checkpoint(
typeof value === "string" ? 64 + value.length * 4 : 128,
);
}
}
}