mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 02:49:12 +00:00
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:
1 parent
49e2eca4f9
commit
4f66985978
22 files changed
+544
-230
No files matched your search
@@ -15,11 +15,9 @@ import {
|
||||
xmlFirstChildNamed,
|
||||
} from "../domain/xmlDocument.js";
|
||||
import {
|
||||
MAVEN_GRADLE_METADATA_DEPENDENCY_ROWS,
|
||||
MAVEN_GRADLE_METADATA_EXCLUSIONS,
|
||||
MAVEN_GRADLE_METADATA_REPEATED_VARIANT_NAME_CHARS,
|
||||
MAVEN_GRADLE_METADATA_VARIANTS,
|
||||
MAVEN_GRADLE_METADATA_XML_NODES,
|
||||
mavenGradleReportLimits,
|
||||
type MavenGradleReportLimitField,
|
||||
type MavenGradleReportLimits,
|
||||
requestedVersionKind,
|
||||
type MavenGradleDependency,
|
||||
type MavenGradleMetadata,
|
||||
@@ -28,7 +26,6 @@ import { redactRecordedTransportUrl } from "../domain/recordedTransportUrl.js";
|
||||
import {
|
||||
MAVEN_GRADLE_METADATA_FORMAT,
|
||||
metadataReportLimit,
|
||||
type MavenGradleReportAllowance,
|
||||
} from "./MavenGradleMetadata.errors.js";
|
||||
|
||||
const BASE_LIMITATIONS = [
|
||||
@@ -81,7 +78,7 @@ const isMavenProjectRoot = (root: Node | null): root is Element => {
|
||||
|
||||
/** Refuse a report whose expanded collection would outgrow its fixed allowance. */
|
||||
const admit = (
|
||||
allowance: MavenGradleReportAllowance,
|
||||
allowance: MavenGradleReportLimitField,
|
||||
limit: number,
|
||||
required: number,
|
||||
): void => {
|
||||
@@ -288,12 +285,13 @@ const parseMavenDependency = <
|
||||
const parsePom = (
|
||||
xml: string,
|
||||
artifact: { path: string; sha256: string; bytes: number },
|
||||
limits: MavenGradleReportLimits,
|
||||
): MavenGradleMetadata => {
|
||||
const limitations: string[] = [...BASE_LIMITATIONS];
|
||||
// Maven applies XML 1.0 end-of-line handling to property and coordinate text.
|
||||
const parsed = parseXmlDocumentWithinNodeLimit(xml, {
|
||||
lineEndings: "normalize",
|
||||
maximumNodes: MAVEN_GRADLE_METADATA_XML_NODES,
|
||||
maximumNodes: limits.xml_nodes,
|
||||
});
|
||||
if (!parsed.ok && parsed.error.kind === "node-limit")
|
||||
throw metadataReportLimit(
|
||||
@@ -317,7 +315,9 @@ const parsePom = (
|
||||
MAVEN_GRADLE_METADATA_FORMAT,
|
||||
"Selected XML document is not a Maven project POM.",
|
||||
);
|
||||
const unresolved = new MavenGradleUnresolvedCollector();
|
||||
const unresolved = new MavenGradleUnresolvedCollector(
|
||||
limits.unresolved_records,
|
||||
);
|
||||
const parentElement = soleNamed(root, "parent");
|
||||
const parent =
|
||||
parentElement === undefined
|
||||
@@ -381,12 +381,12 @@ const parsePom = (
|
||||
);
|
||||
admit(
|
||||
"dependency_rows",
|
||||
MAVEN_GRADLE_METADATA_DEPENDENCY_ROWS,
|
||||
limits.dependency_rows,
|
||||
managedElements.length + dependencyElements.length,
|
||||
);
|
||||
admit(
|
||||
"exclusions",
|
||||
MAVEN_GRADLE_METADATA_EXCLUSIONS,
|
||||
limits.exclusions,
|
||||
[...managedElements, ...dependencyElements].reduce(
|
||||
(count, element) => count + mavenExclusionElements(element).length,
|
||||
0,
|
||||
@@ -485,6 +485,7 @@ const parseGradleDependency = <
|
||||
const parseGradle = (
|
||||
source: string,
|
||||
artifact: { path: string; sha256: string; bytes: number },
|
||||
limits: MavenGradleReportLimits,
|
||||
): MavenGradleMetadata => {
|
||||
const json = parseJsonWithDuplicatePolicy(source, "reject");
|
||||
if (!json.ok) {
|
||||
@@ -534,7 +535,9 @@ const parseGradle = (
|
||||
limitations.push(
|
||||
`Recognized fields in this unfamiliar format version were interpreted using Gradle module metadata ${GRADLE_MODULE_METADATA_VERSION}. Version-specific declarations may be unreported.`,
|
||||
);
|
||||
const unresolved = new MavenGradleUnresolvedCollector();
|
||||
const unresolved = new MavenGradleUnresolvedCollector(
|
||||
limits.unresolved_records,
|
||||
);
|
||||
const coordinates = {
|
||||
group_id: component === null ? null : gradleText(component.group),
|
||||
artifact_id: component === null ? null : gradleText(component.module),
|
||||
@@ -547,7 +550,7 @@ const parseGradle = (
|
||||
// Count each expanded collection before any report record is built.
|
||||
admit(
|
||||
"variants",
|
||||
MAVEN_GRADLE_METADATA_VARIANTS,
|
||||
limits.variants,
|
||||
gradleArray(variantsValue, "variants").length,
|
||||
);
|
||||
const variants = gradleObjects(variantsValue, "variants");
|
||||
@@ -557,7 +560,7 @@ const parseGradle = (
|
||||
]);
|
||||
admit(
|
||||
"dependency_rows",
|
||||
MAVEN_GRADLE_METADATA_DEPENDENCY_ROWS,
|
||||
limits.dependency_rows,
|
||||
rowLists.reduce((count, rows) => count + rows.length, 0),
|
||||
);
|
||||
let exclusions = 0;
|
||||
@@ -565,16 +568,14 @@ const parseGradle = (
|
||||
for (const row of rows)
|
||||
if (isRecord(row))
|
||||
exclusions += gradleArray(row.excludes, "excludes").length;
|
||||
admit("exclusions", MAVEN_GRADLE_METADATA_EXCLUSIONS, exclusions);
|
||||
admit("exclusions", limits.exclusions, exclusions);
|
||||
const dependencies: MavenGradleDependency<"variant-dependencies">[] = [];
|
||||
const dependency_management: MavenGradleDependency<"variant-constraints">[] =
|
||||
[];
|
||||
const gradleVariants: NonNullable<MavenGradleMetadata["gradle"]>["variants"] =
|
||||
[];
|
||||
let nextIndex = 0;
|
||||
const repeatedVariantNames = new Budget(
|
||||
MAVEN_GRADLE_METADATA_REPEATED_VARIANT_NAME_CHARS,
|
||||
);
|
||||
const repeatedVariantNames = new Budget(limits.repeated_variant_name_chars);
|
||||
const variantNameIndices = new Map<string, number>();
|
||||
for (const [index, variant] of variants.entries()) {
|
||||
const declaredName = variant.name;
|
||||
@@ -686,6 +687,7 @@ const parseGradle = (
|
||||
export const parseMavenGradleMetadata = (
|
||||
bytes: Uint8Array,
|
||||
artifact: { path: string; sha256: string; bytes: number },
|
||||
limits: MavenGradleReportLimits = mavenGradleReportLimits(),
|
||||
): MavenGradleMetadata => {
|
||||
if (bytes.length !== artifact.bytes)
|
||||
throw malformedInput(
|
||||
@@ -708,9 +710,9 @@ export const parseMavenGradleMetadata = (
|
||||
}
|
||||
const trimmed = source.trimStart();
|
||||
if (trimmed.startsWith("{") || trimmed.startsWith("["))
|
||||
return parseGradle(source, artifact);
|
||||
return parseGradle(source, artifact, limits);
|
||||
if (opensLikeXml(trimmed) || trimmed.startsWith("<"))
|
||||
return parsePom(source, artifact);
|
||||
return parsePom(source, artifact, limits);
|
||||
throw unsupportedInput(
|
||||
MAVEN_GRADLE_METADATA_FORMAT,
|
||||
"Selected file is not a Maven POM or Gradle module-metadata document.",
|
||||
|
||||
Reference in new issue
Block a user