Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

refactor(process): give the prlimit producer budget one owner (#2698)

The one -Niu782cc3b06056
diff --git a/scripts/verify/architecture-guards.mjs b/scripts/verify/architecture-guards.mjs
index 967e210de..3ca254d7e 100644
--- a/scripts/verify/architecture-guards.mjs
+++ b/scripts/verify/architecture-guards.mjs
@@ -89,6 +89,30 @@ check(
["src/domain/javascript/javascriptSemanticTraversal.ts"],
);
+// A producer that pins both the soft and hard ceiling of every resource must take
+// the vector from one owner. Audited 2026-10-13 against the other prlimit lanes:
+// src/pcap/PcapNativeBound.ts pairs soft and hard but budgets 300 CPU seconds and
+// has no resident-input ceiling; src/evm/EvmoleInterfaceProvider.ts,
+// src/firmware/FirmwareCommand.ts and src/javascript/recovery/WakaruCommand.ts
+// spell soft-only forms (`--core=0:`, `--core=0`). Those four stay as they are;
+// a new paired producer calls prlimitArgumentVector instead of spelling options.
+check(
+ "inline paired prlimit ceilings (use prlimitArgumentVector from src/process/LinuxResourceLimits)",
+ files,
+ /--core=0:0/,
+ ["src/process/LinuxResourceLimits.ts", "src/pcap/PcapNativeBound.ts"],
+);
+
+// Census is spelling-shaped, like the rules above: a lane that expresses the same
+// ceilings differently (`1024 ** 3`, camelCase fields) is not caught here, which is
+// why the four lanes above are listed rather than left to a future reader.
+check(
+ "inline resident-input budget (use BOUNDED_PRODUCER_LIMITS from src/process/LinuxResourceLimits)",
+ files,
+ /input_bytes:\s*32 \* 1024 \* 1024/,
+ ["src/process/LinuxResourceLimits.ts"],
+);
+
// Fixed-arity backtick keys audited 2026-10-10: every prefix field is NUL-free
// (hex digests, file paths, enums, numbers, or compositeKey JSON which escapes
// NUL), with free-form source strings only in final position. New backtick-\0
diff --git a/src/captures/TsharkCaptureProvider.ts b/src/captures/TsharkCaptureProvider.ts
index 23496aac4..c4c89b88e 100644
--- a/src/captures/TsharkCaptureProvider.ts
+++ b/src/captures/TsharkCaptureProvider.ts
@@ -8,6 +8,8 @@ import {
FIELD_RECORD_BUDGET,
} from "./parseFieldDiscovery.js";
import {
+ BOUNDED_PRODUCER_LIMITS as LIMITS,
+ prlimitArgumentVector,
readLinuxResourceLimits,
type LinuxResourceLimits,
} from "../process/LinuxResourceLimits.js";
@@ -60,15 +62,6 @@ export const TSHARK_PROVIDER_IDENTITY = {
name: "REA TShark capture adapter",
version: "tshark@4",
} as const;
-// Bound the resident input copy and retained text before allocation/collection.
-const LIMITS = {
- input_bytes: 32 * 1024 * 1024,
- output_bytes: 4 * 1024 * 1024,
- command_timeout_ms: 30_000,
- address_space_bytes: 1024 * 1024 * 1024,
- file_bytes: 64 * 1024 * 1024,
- cpu_seconds: 30,
-} as const;
type Launcher = NonNullable<Parameters<typeof runOwnedCommand>[2]>["launcher"];
/** Inspect selected capture files only, retaining cleanup ownership across failures. */
@@ -165,14 +158,7 @@ export class TsharkCaptureProvider implements PacketCapturePort {
options?.signal,
);
effectiveLimits = await this.#resources.readLimits(limits);
- const limitArguments = [
- `--as=${effectiveLimits.address_space_bytes}:${effectiveLimits.address_space_bytes}`,
- `--fsize=${effectiveLimits.file_bytes}:${effectiveLimits.file_bytes}`,
- `--cpu=${effectiveLimits.cpu_seconds}:${effectiveLimits.cpu_seconds}`,
- "--core=0:0",
- "--",
- command,
- ];
+ const limitArguments = prlimitArgumentVector(effectiveLimits, command);
phase = "workspace";
root = await this.createRuntime();
this.#resources.retain(root, undefined);
diff --git a/src/process/LinuxResourceLimits.test.ts b/src/process/LinuxResourceLimits.test.ts
index 69a584d74..0b19f773e 100644
--- a/src/process/LinuxResourceLimits.test.ts
+++ b/src/process/LinuxResourceLimits.test.ts
@@ -1,5 +1,9 @@
import { expect, it } from "vitest";
-import { clampLinuxResourceLimits } from "./LinuxResourceLimits.js";
+import {
+ BOUNDED_PRODUCER_LIMITS,
+ clampLinuxResourceLimits,
+ prlimitArgumentVector,
+} from "./LinuxResourceLimits.js";
const configured = {
address_space_bytes: 1073741824,
file_bytes: 67108864,
@@ -41,3 +45,38 @@ it("refuses missing, ambiguous or malformed kernel limits before launch", () =>
])
expect(() => clampLinuxResourceLimits(configured, value)).toThrow();
});
+it("pins the shared producer budget in one place", () => {
+ expect(BOUNDED_PRODUCER_LIMITS).toEqual({
+ input_bytes: 33554432,
+ output_bytes: 4194304,
+ command_timeout_ms: 30000,
+ address_space_bytes: 1073741824,
+ file_bytes: 67108864,
+ cpu_seconds: 30,
+ });
+});
+it("pairs each effective ceiling with itself before the producer argv", () => {
+ expect(
+ prlimitArgumentVector(BOUNDED_PRODUCER_LIMITS, "/bin/producer"),
+ ).toEqual([
+ "--as=1073741824:1073741824",
+ "--fsize=67108864:67108864",
+ "--cpu=30:30",
+ "--core=0:0",
+ "--",
+ "/bin/producer",
+ ]);
+ expect(
+ prlimitArgumentVector(
+ clampLinuxResourceLimits(BOUNDED_PRODUCER_LIMITS, report("10 20")),
+ "/bin/producer",
+ ),
+ ).toEqual([
+ "--as=10:10",
+ "--fsize=67108864:67108864",
+ "--cpu=30:30",
+ "--core=0:0",
+ "--",
+ "/bin/producer",
+ ]);
+});
diff --git a/src/process/LinuxResourceLimits.ts b/src/process/LinuxResourceLimits.ts
index e6eefcefe..414eb13bb 100644
--- a/src/process/LinuxResourceLimits.ts
+++ b/src/process/LinuxResourceLimits.ts
@@ -15,6 +15,29 @@ const rows = {
cpu_seconds: "Max cpu time",
} as const;
+/** Bound the resident input copy and retained text before allocation/collection. */
+export const BOUNDED_PRODUCER_LIMITS = {
+ input_bytes: 32 * 1024 * 1024,
+ output_bytes: 4 * 1024 * 1024,
+ command_timeout_ms: 30_000,
+ address_space_bytes: 1024 * 1024 * 1024,
+ file_bytes: 64 * 1024 * 1024,
+ cpu_seconds: 30,
+} as const;
+
+/** Pin soft and hard ceilings together, then hand the producer argv to the limiter. */
+export const prlimitArgumentVector = (
+ limits: LinuxResourceLimits,
+ command: string,
+): string[] => [
+ `--as=${limits.address_space_bytes}:${limits.address_space_bytes}`,
+ `--fsize=${limits.file_bytes}:${limits.file_bytes}`,
+ `--cpu=${limits.cpu_seconds}:${limits.cpu_seconds}`,
+ "--core=0:0",
+ "--",
+ command,
+];
+
/** Never raise either inherited soft policy or hard ceiling. */
export const clampLinuxResourceLimits = (
configured: LinuxResourceLimits,
diff --git a/src/signals/SigrokRecordingProvider.ts b/src/signals/SigrokRecordingProvider.ts
index f5f823a1a..541138a6a 100644
--- a/src/signals/SigrokRecordingProvider.ts
+++ b/src/signals/SigrokRecordingProvider.ts
@@ -7,6 +7,8 @@ import {
parseDecoderDiscovery,
} from "./parseDecoderDiscovery.js";
import {
+ BOUNDED_PRODUCER_LIMITS as LIMITS,
+ prlimitArgumentVector,
readLinuxResourceLimits,
type LinuxResourceLimits,
} from "../process/LinuxResourceLimits.js";
@@ -59,15 +61,6 @@ export const SIGROK_PROVIDER_IDENTITY = {
name: "REA sigrok recording adapter",
version: "[email protected]",
} as const;
-// Bound the resident input copy and retained text before allocation/collection.
-const LIMITS = {
- input_bytes: 32 * 1024 * 1024,
- output_bytes: 4 * 1024 * 1024,
- command_timeout_ms: 30_000,
- address_space_bytes: 1024 * 1024 * 1024,
- file_bytes: 64 * 1024 * 1024,
- cpu_seconds: 30,
-} as const;
type Launcher = NonNullable<Parameters<typeof runOwnedCommand>[2]>["launcher"];
/** Decode selected recordings only, retaining cleanup ownership across failures. */
@@ -163,14 +156,7 @@ export class SigrokRecordingProvider implements SignalRecordingPort {
options?.signal,
);
effectiveLimits = await this.#resources.readLimits(LIMITS);
- const limitArguments = [
- `--as=${effectiveLimits.address_space_bytes}:${effectiveLimits.address_space_bytes}`,
- `--fsize=${effectiveLimits.file_bytes}:${effectiveLimits.file_bytes}`,
- `--cpu=${effectiveLimits.cpu_seconds}:${effectiveLimits.cpu_seconds}`,
- "--core=0:0",
- "--",
- command,
- ];
+ const limitArguments = prlimitArgumentVector(effectiveLimits, command);
phase = "workspace";
root = await this.createRuntime();
this.#resources.retain(root, undefined);