mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 11:33:10 +00:00
fix(errors): let typed limit refusals state recovery from the measured requirement (#15447)
Several limit refusals wrote their own "raise X up to MAX" text, which replaced the shared adjustable-budget recovery and advised a value that cannot admit the input when the measured requirement is above the control's maximum. Following #15407 (VSIX and pyc), these producers now report a typed limit with the measured requirement and no prose: - NuGet parse budgets, as VSIX already does. - The selected-file size budget of NuGet, VSIX, Maven/Gradle metadata, ESP NVS, release exposure and NTFS journal reads. The reader's observed file size becomes required_value through the new selectedFileRequirement helper. - IL2CPP's native pointer index budget. inspect_packet_capture's DNS limitation no longer says to raise dns_identity_limit's control when it is already at its maximum or the requirement is above it. The unused imageFileSizeRemediation is removed. Refs #15325
This commit is contained in:
1 parent
5a0ab31812
commit
3070116222
12 files changed
+123
-72
No files matched your search
@@ -14,6 +14,7 @@ import {
|
||||
assertStableArtifactState,
|
||||
projectStableArtifactFailure,
|
||||
stableArtifactInputOptions,
|
||||
selectedFileRequirement,
|
||||
readerIntegrityFailure,
|
||||
} from "../../resources/index.js";
|
||||
import {
|
||||
@@ -68,6 +69,8 @@ const acquisitionConstraint = (
|
||||
message: string,
|
||||
maxFileBytes: number,
|
||||
cause?: Error,
|
||||
/** The acquisition's measured size, for a budget refusal. */
|
||||
requiredBytes?: number,
|
||||
): AnalysisError =>
|
||||
new AnalysisResourceConstraintError(
|
||||
operation,
|
||||
@@ -84,11 +87,12 @@ const acquisitionConstraint = (
|
||||
}
|
||||
: {
|
||||
retryable: false,
|
||||
limit: ntfsJournalFileBytesLimit(maxFileBytes),
|
||||
remediationAction:
|
||||
maxFileBytes < NTFS_JOURNAL_FILE_BYTES.maximum
|
||||
? `Raise max_file_bytes above ${String(maxFileBytes)} bytes on the next call for the same acquisitions; both are read into memory.`
|
||||
: "max_file_bytes is at its maximum; select a smaller acquisition.",
|
||||
limit: {
|
||||
...ntfsJournalFileBytesLimit(maxFileBytes),
|
||||
...(requiredBytes === undefined
|
||||
? {}
|
||||
: { required_value: requiredBytes }),
|
||||
},
|
||||
}),
|
||||
},
|
||||
);
|
||||
@@ -120,6 +124,7 @@ const readFailure = (
|
||||
cause.message,
|
||||
maxFileBytes,
|
||||
cause,
|
||||
selectedFileRequirement(cause).required_value,
|
||||
);
|
||||
}
|
||||
if (
|
||||
@@ -169,6 +174,8 @@ const readAcquisition = async (
|
||||
"budget",
|
||||
`The retained ${parameter} acquisition has ${String(cached.snapshot.bytes.length)} bytes, above max_file_bytes (${String(maxFileBytes)}).`,
|
||||
maxFileBytes,
|
||||
undefined,
|
||||
cached.snapshot.bytes.length,
|
||||
),
|
||||
);
|
||||
await assertStableArtifactState(path, cached.state, signal);
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
artifactFileCancellationError,
|
||||
artifactFilePrimaryFacts,
|
||||
projectStableArtifactFailure,
|
||||
selectedFileRequirement,
|
||||
readerIntegrityFailure,
|
||||
type ArtifactFilePrimaryFacts,
|
||||
} from "../../resources/index.js";
|
||||
@@ -17,10 +18,7 @@ import {
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { RELEASE_EXPOSURE_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import {
|
||||
RELEASE_EXPOSURE_FILE_BYTES,
|
||||
releaseExposureFileBytesLimit,
|
||||
} from "../../domain/releaseExposure.js";
|
||||
import { releaseExposureFileBytesLimit } from "../../domain/releaseExposure.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { isSelectedRegularFileError } from "../../filesystem/RegularFile.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
@@ -28,15 +26,6 @@ import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
export const RELEASE_EXPOSURE_AUDIT_OPERATION = "audit_release_exposure";
|
||||
const PROVIDER_ID = RELEASE_EXPOSURE_PROVIDER.id;
|
||||
|
||||
const fileSizeRecovery = (maxFileBytes: number) => ({
|
||||
retryable: false as const,
|
||||
limit: releaseExposureFileBytesLimit(maxFileBytes),
|
||||
remediationAction:
|
||||
maxFileBytes < RELEASE_EXPOSURE_FILE_BYTES.maximum
|
||||
? `Raise max_file_bytes above ${String(maxFileBytes)} bytes (up to ${String(RELEASE_EXPOSURE_FILE_BYTES.maximum)}) on the next call for the same artifact, or select a smaller artifact. Reads are held in memory.`
|
||||
: `max_file_bytes is at its maximum of ${String(maxFileBytes)} bytes; select a smaller artifact.`,
|
||||
});
|
||||
|
||||
/**
|
||||
* The header admission is its own bound, not the selected-file ceiling, so
|
||||
* max_file_bytes cannot repair it. The recovery names the shared setting the
|
||||
@@ -85,7 +74,14 @@ export const releaseExposureLimitFailure = (
|
||||
"file-size",
|
||||
cause.message,
|
||||
{ max_file_bytes: maxFileBytes },
|
||||
{ cause, ...fileSizeRecovery(maxFileBytes) },
|
||||
{
|
||||
cause,
|
||||
retryable: false,
|
||||
limit: {
|
||||
...releaseExposureFileBytesLimit(maxFileBytes),
|
||||
...selectedFileRequirement(cause),
|
||||
},
|
||||
},
|
||||
)
|
||||
: asarHeaderAdmissionFailure(cause, cause.admission);
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ import {
|
||||
projectStableArtifactFailure,
|
||||
readStableArtifact,
|
||||
type StableArtifactSnapshot,
|
||||
selectedFileRequirement,
|
||||
} from "../../resources/index.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { EspNvsPort } from "../../ports/binaryDiagnostics/EspNvsPort.js";
|
||||
import {
|
||||
ESP_NVS_PAGE_BYTES,
|
||||
MAX_ESP_NVS_FILE_BYTES,
|
||||
espNvsBudgetLimit,
|
||||
type EspNvsProviderInput,
|
||||
} from "../../domain/firmware/espNvs.js";
|
||||
@@ -115,11 +115,6 @@ export class EspNvsProvider implements EspNvsPort {
|
||||
}
|
||||
}
|
||||
|
||||
const fileSizeRemediation = (input: EspNvsProviderInput): string =>
|
||||
input.max_file_bytes >= MAX_ESP_NVS_FILE_BYTES
|
||||
? `The image exceeds the ${String(MAX_ESP_NVS_FILE_BYTES)}-byte input ceiling this operation accepts; carve the NVS partition first.`
|
||||
: `Raise max_file_bytes above ${String(input.max_file_bytes)} bytes within its ${String(MAX_ESP_NVS_FILE_BYTES)}-byte ceiling, or carve the NVS partition first.`;
|
||||
|
||||
const espNvsFailure = (
|
||||
cause: unknown,
|
||||
input: EspNvsProviderInput,
|
||||
@@ -160,8 +155,10 @@ const espNvsFailure = (
|
||||
),
|
||||
{
|
||||
retryable: false,
|
||||
limit: espNvsBudgetLimit("max_file_bytes", input.max_file_bytes),
|
||||
remediationAction: fileSizeRemediation(input),
|
||||
limit: {
|
||||
...espNvsBudgetLimit("max_file_bytes", input.max_file_bytes),
|
||||
...selectedFileRequirement(failure),
|
||||
},
|
||||
},
|
||||
),
|
||||
}),
|
||||
|
||||
@@ -121,11 +121,14 @@ const failureForPrimary = (
|
||||
isParseLimit(cause, IL2CPP_BINARY_FORMAT) &&
|
||||
cause.failure.limit.name === ELF_VIRTUAL_POINTER_INDEX_LIMIT
|
||||
) {
|
||||
const selected = cause.failure.limit.maximum;
|
||||
const { maximum: selected, required } = cause.failure.limit;
|
||||
// The typed limit lets the shared refusal owner state the recovery.
|
||||
return parseLimitConstraint(OPERATION, "memory", cause, {
|
||||
retryable: false,
|
||||
limit: il2cppNativeIndexLimit(selected),
|
||||
remediationAction: `The ELF pointer index allowance is max_native_index_bytes = ${String(selected)} bytes. Pass a larger max_native_index_bytes (up to ${String(Number.MAX_SAFE_INTEGER)}) on the next ${OPERATION} call with the same binary_path; no restart is required. Host memory and the binary file allowance are independent. Repeating the unchanged request fails the same way.`,
|
||||
limit: {
|
||||
...il2cppNativeIndexLimit(selected),
|
||||
...(typeof required === "number" ? { required_value: required } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
if (
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
readStableArtifact,
|
||||
translateArtifactFailure,
|
||||
type StableArtifactSnapshot,
|
||||
selectedFileRequirement,
|
||||
} from "../resources/index.js";
|
||||
import {
|
||||
isParseLimit,
|
||||
@@ -17,7 +18,6 @@ import { xmlElementDepthConstraint } from "../domain/xmlDocument.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
import { ArtifactOperationError } from "../domain/artifactOperationError.js";
|
||||
import {
|
||||
MAVEN_GRADLE_FILE_BYTES,
|
||||
mavenGradleFileBytesLimit,
|
||||
mavenGradleReportLimit,
|
||||
mavenGradleReportLimits,
|
||||
@@ -84,13 +84,6 @@ export class MavenGradleMetadataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
const inputBudgetRemediation = (
|
||||
input: InspectMavenGradleMetadataInput,
|
||||
): string =>
|
||||
input.max_file_bytes >= MAVEN_GRADLE_FILE_BYTES.maximum
|
||||
? `The file exceeds the ${String(MAVEN_GRADLE_FILE_BYTES.maximum)}-byte input ceiling this operation accepts; select a smaller artifact.`
|
||||
: `Raise max_file_bytes above ${String(input.max_file_bytes)} bytes, up to ${String(MAVEN_GRADLE_FILE_BYTES.maximum)}, or select a smaller artifact; this is the caller-selected input read budget.`;
|
||||
|
||||
const REPORT_LIMIT_FIELDS = Object.keys(
|
||||
MAVEN_GRADLE_REPORT_LIMIT_BOUNDS,
|
||||
) as MavenGradleReportLimitField[];
|
||||
@@ -152,8 +145,10 @@ const mavenGradleMetadataFailure = (
|
||||
),
|
||||
{
|
||||
retryable: false,
|
||||
limit: mavenGradleFileBytesLimit(input.max_file_bytes),
|
||||
remediationAction: inputBudgetRemediation(input),
|
||||
limit: {
|
||||
...mavenGradleFileBytesLimit(input.max_file_bytes),
|
||||
...selectedFileRequirement(failure),
|
||||
},
|
||||
},
|
||||
),
|
||||
unclassified: (failure, origin) =>
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
projectStableArtifactFailure,
|
||||
translateArtifactFailure,
|
||||
withStableArtifactHandle,
|
||||
selectedFileRequirement,
|
||||
} from "../resources/index.js";
|
||||
import {
|
||||
isParseLimit,
|
||||
@@ -31,13 +32,24 @@ import { parseNugetNupkg } from "./NugetNupkgParser.js";
|
||||
|
||||
const OPERATION = "inspect_nuget_nupkg";
|
||||
|
||||
/** The refusal options for an exhausted per-call budget. */
|
||||
const budgetRecovery = (parameter: NugetNupkgBudget, selected: number) => ({
|
||||
limit: nugetNupkgBudgetLimit(parameter, selected),
|
||||
remediationAction:
|
||||
selected >= NUGET_NUPKG_BUDGETS[parameter].maximum
|
||||
? `${parameter} is at this operation's maximum of ${String(NUGET_NUPKG_BUDGETS[parameter].maximum)}; select a complete artifact within that bound.`
|
||||
: `Raise ${parameter} above ${String(selected)}, up to ${String(NUGET_NUPKG_BUDGETS[parameter].maximum)}, or select a smaller artifact. The budget applies on the next call; repeating the unchanged request does not raise it.`,
|
||||
/**
|
||||
* The typed limit of an exhausted per-call budget, so the shared refusal
|
||||
* owner states the recovery. An early-stop read measures only a lower bound
|
||||
* of the requirement, so it is reported as `required_value` only when even
|
||||
* that bound exceeds the control's maximum: raising the budget cannot help.
|
||||
*/
|
||||
const budgetRecovery = (
|
||||
parameter: NugetNupkgBudget,
|
||||
selected: number,
|
||||
required?: number | bigint,
|
||||
) => ({
|
||||
limit: {
|
||||
...nugetNupkgBudgetLimit(parameter, selected),
|
||||
...(typeof required === "number" &&
|
||||
required > NUGET_NUPKG_BUDGETS[parameter].maximum
|
||||
? { required_value: required }
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
|
||||
const nupkgFailure = (
|
||||
@@ -71,7 +83,11 @@ const nupkgFailure = (
|
||||
retryable: false,
|
||||
...(parameter === undefined
|
||||
? {}
|
||||
: budgetRecovery(parameter, failure.failure.limit.maximum)),
|
||||
: budgetRecovery(
|
||||
parameter,
|
||||
failure.failure.limit.maximum,
|
||||
failure.failure.limit.required,
|
||||
)),
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -113,7 +129,10 @@ const nupkgFailure = (
|
||||
),
|
||||
{
|
||||
retryable: false,
|
||||
...budgetRecovery("max_file_bytes", input.max_file_bytes),
|
||||
limit: {
|
||||
...nugetNupkgBudgetLimit("max_file_bytes", input.max_file_bytes),
|
||||
...selectedFileRequirement(failure),
|
||||
},
|
||||
},
|
||||
),
|
||||
unclassified: (failure) =>
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
PCAP_CAPTURE_HOST_REMEDIATION,
|
||||
type PcapRequest,
|
||||
type PcapOperation,
|
||||
PCAP_PRODUCER_LIMITS,
|
||||
} from "../domain/pcap/pcapAnalysis.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
@@ -57,7 +58,6 @@ import {
|
||||
parseCapinfosOutput,
|
||||
prepareTsharkBaseOutput,
|
||||
} from "./PcapOutput.js";
|
||||
import { PCAP_PRODUCER_LIMITS } from "../domain/pcap/pcapAnalysis.js";
|
||||
import type { AnalysisParameterLimit } from "../domain/analysisSettings.js";
|
||||
import { resolveProducerLimits } from "../domain/producerResourceLimits.js";
|
||||
import {
|
||||
@@ -288,6 +288,16 @@ class RetainedSnapshotFailure implements AnalysisCleanupReleaseClaim {
|
||||
}
|
||||
|
||||
/** Inspect saved captures through bounded, owned tool processes and one stable input copy. */
|
||||
/**
|
||||
* Whether raising the DNS pass's limit can run it: not when the limit is
|
||||
* already at its maximum or the measured requirement is above it.
|
||||
*/
|
||||
const dnsLimitRecovery = (limit: AnalysisParameterLimit): string =>
|
||||
limit.effective_value >= limit.maximum ||
|
||||
(limit.required_value !== undefined && limit.required_value > limit.maximum)
|
||||
? `it cannot be raised far enough (maximum ${String(limit.maximum)}), so the DNS pass cannot run on this capture`
|
||||
: "raise it on the next call to run the DNS pass";
|
||||
|
||||
export class PcapProvider {
|
||||
readonly #resources: ArtifactAnalysisResources;
|
||||
private readonly environment: Readonly<Record<string, string | undefined>>;
|
||||
@@ -1299,7 +1309,7 @@ export class PcapProvider {
|
||||
cause.limit.control_kind === "parameter"
|
||||
)
|
||||
dnsIdentityLimit = cause.limit;
|
||||
dnsLimitation = `DNS wire identity extraction was unavailable: ${dnsFailureReason(cause)}; producer queries and addresses are retained without inferred ownership${dnsIdentityLimit === undefined ? "" : `. dns_identity_limit names ${dnsIdentityLimit.parameter}; raise it on the next call to run the DNS pass`}`;
|
||||
dnsLimitation = `DNS wire identity extraction was unavailable: ${dnsFailureReason(cause)}; producer queries and addresses are retained without inferred ownership${dnsIdentityLimit === undefined ? "" : `. dns_identity_limit names ${dnsIdentityLimit.parameter}; ${dnsLimitRecovery(dnsIdentityLimit)}`}`;
|
||||
}
|
||||
} else {
|
||||
dnsLimitation =
|
||||
|
||||
@@ -18,7 +18,6 @@ import { translateArtifactFailure } from "./ArtifactOperationFailure.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { constants as bufferConstants } from "node:buffer";
|
||||
import {
|
||||
imageFileSizeRemediation,
|
||||
projectOwnedArtifactInputFailure,
|
||||
projectStableArtifactFailure,
|
||||
readerIntegrityFailure,
|
||||
@@ -222,16 +221,6 @@ it("leaves opaque operation errors and decode limits with their owning projectio
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
// The provider ceiling test uses a sparse file and is skipped on Windows.
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"names the fixed image ceiling when the selected budget is already maximal",
|
||||
() => {
|
||||
expect(imageFileSizeRemediation(1024, 1024)).toContain(
|
||||
"no runtime override",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ effective: 1, required: bufferConstants.MAX_STRING_LENGTH + 1 },
|
||||
{ effective: bufferConstants.MAX_STRING_LENGTH, required: undefined },
|
||||
|
||||
@@ -174,14 +174,18 @@ export const projectSelectedArtifactFileFailure = (
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/** Explain the selected image read budget and its fixed upper bound. */
|
||||
export const imageFileSizeRemediation = (
|
||||
selectedBytes: number,
|
||||
maximumBytes: number,
|
||||
): string =>
|
||||
selectedBytes >= maximumBytes
|
||||
? `The image exceeds the ${String(maximumBytes)}-byte input ceiling this operation accepts. This release has no runtime override. Select a smaller artifact.`
|
||||
: `Raise max_file_bytes above ${String(selectedBytes)} bytes or select a smaller artifact; the limit is the caller-selected input read budget.`;
|
||||
/**
|
||||
* The selected file's measured size as a refused file-size budget's
|
||||
* `required_value`, so the shared refusal owner can say whether raising the
|
||||
* budget can admit the file.
|
||||
*/
|
||||
export const selectedFileRequirement = (
|
||||
cause: ArtifactReaderFailure,
|
||||
): { readonly required_value?: number } =>
|
||||
cause.observedBytes !== undefined &&
|
||||
cause.observedBytes <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? { required_value: Number(cause.observedBytes) }
|
||||
: {};
|
||||
|
||||
/** Name an observed regular-file retry that admission will validate again. */
|
||||
export const regularFileSymlinkRecovery = (resolvedPath: string): string =>
|
||||
|
||||
@@ -98,7 +98,7 @@ export type {
|
||||
RetainedResourceScope,
|
||||
} from "./ArtifactResourceScope.js";
|
||||
export {
|
||||
imageFileSizeRemediation,
|
||||
selectedFileRequirement,
|
||||
closeArtifactResources,
|
||||
artifactFileCleanupError,
|
||||
projectArtifactCloseFailure,
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
readStableArtifact,
|
||||
translateArtifactFailure,
|
||||
type StableArtifactSnapshot,
|
||||
selectedFileRequirement,
|
||||
} from "../resources/index.js";
|
||||
import {
|
||||
classifyProviderFailure,
|
||||
@@ -78,7 +79,10 @@ const vsixFileSizeFailure = (
|
||||
{
|
||||
...details,
|
||||
retryable: false,
|
||||
...budgetRecovery("max_file_bytes", input.max_file_bytes),
|
||||
limit: {
|
||||
...vsixPackageBudgetLimit("max_file_bytes", input.max_file_bytes),
|
||||
...selectedFileRequirement(cause),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -148,6 +148,33 @@ mcpTest(
|
||||
},
|
||||
);
|
||||
|
||||
mcpTest(
|
||||
"does not advise a larger budget than the maximum a measured .nuspec needs",
|
||||
async ({ mcp }) => {
|
||||
const { client, session } = await connect(mcp);
|
||||
try {
|
||||
const root = await createTestTempDirectory("rea-nupkg-mcp-nuspec-");
|
||||
const path = join(root, "Large.Nuspec.nupkg");
|
||||
// A .nuspec one byte past the 16 MiB max_nuspec_bytes maximum.
|
||||
const maximum = 16 * 1024 * 1024;
|
||||
const nuspec = `<!--${"x".repeat(maximum - 6)}-->`;
|
||||
await writeFile(path, await nugetNupkgFixture({ nuspec }));
|
||||
const response = await client.callTool({
|
||||
name: "inspect_nuget_nupkg",
|
||||
arguments: { path, max_nuspec_bytes: 1024 },
|
||||
});
|
||||
const { error } = parseMcpToolError(response);
|
||||
expect(error.code).toBe("resource_constraint");
|
||||
expect(error.remediation.action).toContain(
|
||||
`The request requires ${String(maximum + 1)} bytes, above the max_nuspec_bytes maximum`,
|
||||
);
|
||||
expect(error.remediation.action).not.toMatch(/Raise max_nuspec_bytes/u);
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
mcpTest(
|
||||
"summarizes a package over the agent result budget and keeps complete Evidence retained",
|
||||
async ({ mcp }) => {
|
||||
|
||||
Reference in new issue
Block a user