feat(metadata)!: give NTFS, Maven report and NuGet budgets typed per-call controls (#14629)

* feat(metadata)!: give NTFS, Maven report and NuGet budgets typed per-call controls

inspect_ntfs_journal refused acquisitions above a fixed 64 MiB allowance;
it now takes max_file_bytes (default 64 MiB) and re-admits a retained
acquisition under the call's budget, so lowering it cannot reuse a larger
cached read. inspect_maven_gradle_metadata refused at six fixed report
allowances; they are now report_limits fields (CLI --report-limits JSON)
with today's values as defaults. Maven max_file_bytes and NuGet
max_file_bytes, max_entries and max_nuspec_bytes refusals now report
details.limit from the same bounds objects the schemas use.

The Ghidra installation-properties read allowance is registered as a
protocol bound: it reads the provider's own short installation
descriptor, not analysis input.

BREAKING CHANGE: NTFS and Maven report refusals report details.limit
instead of a fixed_ceiling refusal, and parseMavenGradleMetadata and the
inspect_ntfs_journal input contract gain the new controls.

* fix(metadata): keep omitted NTFS budgets omitted and type host and maximum recovery

inspect_ntfs_journal recorded the default max_file_bytes as if the caller
had chosen it; the field is now optional and resolved for execution only,
so Evidence keeps omission. A host allocation failure while holding an
admitted acquisition is reported as measured memory exhaustion instead
of generic I/O. A Maven report refusal whose need exceeds the control's
maximum no longer suggests raising it. A public CLI/MCP test covers
report_limits refusal and recovery for a POM.
This commit is contained in:
morluto authored and GitHub committed 2026-11-25 21:55:28 -05:00
1 parent 49e2eca4f9
commit 4f66985978
22 files changed
+544 -230

No files matched your search

+40 -51
View File
@@ -16,15 +16,16 @@ import { decodeLimit } from "../domain/parseFailure.js";
import { errorMessage } from "../kernel/errorMessage.js";
import { ArtifactOperationError } from "../domain/artifactOperationError.js";
import {
MAX_INSPECT_MAVEN_GRADLE_METADATA_FILE_BYTES,
MAVEN_GRADLE_FILE_BYTES,
mavenGradleFileBytesLimit,
mavenGradleReportLimit,
mavenGradleReportLimits,
MAVEN_GRADLE_REPORT_LIMIT_BOUNDS,
type MavenGradleReportLimitField,
type InspectMavenGradleMetadataInput,
} from "../domain/java/mavenGradleMetadata.js";
import { err, ok } from "../domain/result.js";
import {
MAVEN_GRADLE_METADATA_FORMAT,
type MavenGradleReportAllowance,
} from "./MavenGradleMetadata.errors.js";
import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js";
import { MAVEN_GRADLE_METADATA_FORMAT } from "./MavenGradleMetadata.errors.js";
import { MAVEN_GRADLE_METADATA_PROVIDER_IDENTITY } from "./MavenGradleMetadataProviderIdentity.js";
import { parseMavenGradleMetadata } from "./MavenGradleMetadataParser.js";
import { classifyProviderFailure } from "../providers/classifyProviderFailure.js";
@@ -65,11 +66,15 @@ export class MavenGradleMetadataProvider {
this.#resources,
);
return ok(
parseMavenGradleMetadata(snapshot.bytes, {
path: input.path,
sha256: snapshot.sha256,
bytes: snapshot.bytes.length,
}),
parseMavenGradleMetadata(
snapshot.bytes,
{
path: input.path,
sha256: snapshot.sha256,
bytes: snapshot.bytes.length,
},
mavenGradleReportLimits(input.report_limits),
),
);
});
} catch (cause) {
@@ -81,27 +86,13 @@ export class MavenGradleMetadataProvider {
const inputBudgetRemediation = (
input: InspectMavenGradleMetadataInput,
): string =>
input.max_file_bytes >= MAX_INSPECT_MAVEN_GRADLE_METADATA_FILE_BYTES
? `The file exceeds the ${String(MAX_INSPECT_MAVEN_GRADLE_METADATA_FILE_BYTES)}-byte input ceiling this operation accepts; select a smaller artifact.`
: `Raise max_file_bytes above ${String(input.max_file_bytes)} bytes, up to ${String(MAX_INSPECT_MAVEN_GRADLE_METADATA_FILE_BYTES)}, or select a smaller artifact; this is the caller-selected input read budget.`;
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.`;
/** The subject a fixed-allowance remediation names for each report allowance. */
const REPORT_ALLOWANCE_SUBJECTS: Readonly<
Record<MavenGradleReportAllowance, (limit: number) => string>
> = {
dependency_rows: (limit) =>
`The ${String(limit)}-row allowance for dependency and constraint rows`,
variants: (limit) =>
`The ${String(limit)}-variant allowance for Gradle module variants`,
exclusions: (limit) =>
`The ${String(limit)}-exclusion allowance for dependency exclusions`,
unresolved_records: (limit) =>
`The ${String(limit)}-record allowance for unresolved references and coordinates`,
xml_nodes: (limit) =>
`The ${String(limit)}-node allowance for a Maven POM document tree`,
repeated_variant_name_chars: (limit) =>
`The ${String(limit)}-character allowance for variant names repeated across Gradle dependency rows`,
};
const REPORT_LIMIT_FIELDS = Object.keys(
MAVEN_GRADLE_REPORT_LIMIT_BOUNDS,
) as MavenGradleReportLimitField[];
const mavenGradleMetadataFailure = (
cause: unknown,
@@ -121,28 +112,25 @@ const mavenGradleMetadataFailure = (
recognise: (failure) => {
if (!isParseLimit(failure, MAVEN_GRADLE_METADATA_FORMAT))
return undefined;
const { name, maximum } = failure.failure.limit;
const { name, maximum, required } = failure.failure.limit;
const field = REPORT_LIMIT_FIELDS.find((field) => field === name);
const limit =
field === undefined
? undefined
: mavenGradleReportLimit(field, maximum);
return parseLimitConstraint(OPERATION, "memory", failure, {
path: input.path,
...fixedAllowanceOptions(
Object.entries(REPORT_ALLOWANCE_SUBJECTS).find(
([key]) => key === name,
)?.[1](maximum) ?? name,
name === "xml_nodes" ? "parser" : "report",
{
limit: maximum,
unit:
name === "repeated_variant_name_chars"
? "UTF-16 code units"
: name === "unresolved_records"
? "records"
: name === "dependency_rows"
? "rows"
: name === "xml_nodes"
? "nodes"
: name,
},
),
retryable: false,
...(limit === undefined
? {}
: {
limit,
remediationAction:
maximum < limit.maximum &&
(required === undefined || required <= limit.maximum)
? `Pass a larger ${limit.parameter}${required === undefined ? "" : ` (at least ${String(required)})`} on the next call for the same document; no restart is required.`
: `${limit.parameter} cannot exceed ${String(limit.maximum)}, which does not admit this document; select a document within that bound.`,
}),
});
},
fileSize: (failure) =>
@@ -157,6 +145,7 @@ const mavenGradleMetadataFailure = (
),
{
retryable: false,
limit: mavenGradleFileBytesLimit(input.max_file_bytes),
remediationAction: inputBudgetRemediation(input),
},
),