mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
* fix(zstd): share exact-frame Zstandard decoding across ELF and OTA Walk RFC 8878 frames once so ELF sections, Android OTA REPLACE_ZSTD, and GPU payloads reject truncated headers, blocks, checksums, and trailing bytes on every supported Node runtime. Bound that walk with the runtime zstd.max_frames setting. * fix(zstd): keep frame output tight and report GPU frame-cap refusals Copy each Node 22 frame off its decoder chunk before the next frame is decoded. Map a GPU zstd.max_frames refusal through the resource-limit contract instead of a provider failure. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): keep frame-cap refusals and bad seeds out of malformed results Project zstd.max_frames through one resource-limit helper for ELF notes, DWARF, GPU, and artifact reads. An invalid REA_ZSTD_MAX_FRAMES seed stays a configuration failure, and frame-header tests cover content size, window, dictionary id, and RLE blocks. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): yield GPU frame decoding so cancellation can land The frame-by-frame fallback awaits a caller pause before each data frame. GPU yields and checks the read signal there, so a many-frame payload does not finish before a disconnect is observed. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): advertise the frame cap and keep strict GPU decode cancellable List every operation that enforces zstd.max_frames, including GPU, DWARF, and ELF notes. The strict sequence uses the async decoder and checks the caller signal again after it returns, and a single output buffer is not copied a second time. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): refresh analysis-setting schemas and GPU frame-cap projection Regenerate the advertised input summaries for inspect_analysis_settings and update_analysis_settings. GPU inventory now throws the projected zstd.max_frames resource limit from payload decode and #retainFailure, so the adjustable setting survives the public failure. Co-authored-by: morluto <morluto@users.noreply.github.com> * style(gpu): format the frame-cap projection throw oxfmt keeps the zstd.max_frames throw in #retainFailure on one line so CI format:check matches the local formatter. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): yield after the last frame-by-frame GPU decode The fallback returned success in the same turn as the final synchronous frame, so a queued abort was still invisible to the caller's signal check. Pause once more before that success, matching the strict sequence. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): yield ELF, OTA, and DWARF frame decoding on the caller signal The synchronous frame loop ignored abort signals owned by inspect_elf_notes, inspect_dwarf_units, and Android OTA partition reads. Those callers now use the cooperative decoder and yield before Zstandard work, and 32-frame cancellations cover each path. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): observe cancellation during structural parsing * fix(zstd): project section-name frame caps at the ELF directory boundary readElfDirectoryFromBuffer now requires the caller's operation and throws the adjustable zstd.max_frames resource limit. Hardening, unwind, and the other directory consumers keep that typed refusal instead of an adapter or I/O error. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(zstd): preserve optional ELF evidence when frames are capped * fix(zip): validate Zstandard members through frame completion (#12461) fix(zip): require complete Zstandard member frames * fix(elf): yield hardening section name decoding * fix(elf): yield section names for unwind and export reads * fix(zstd): yield ELF directory reads that already own a cancellation signal Hardening, unwind, initializers, exports, kernel modules, debug link, and Android JNI now read section names through the cooperative directory when their caller has a signal. Readers with no signal stay synchronous. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(elf): share one initializer directory and retain its snapshot * fix(android): reuse the admitted JNI ELF directory * fix(elf): retain optional debug candidate evidence through cooperative decoding * fix(zstd): yield ELF section names for Go, Rust, and IL2CPP These inspections already own an abort signal. Their ELF directory read now uses the cooperative container decoder so a queued cancellation can land during a many-frame section-name table. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(elf): recognize compressed kernel modules before ELF decoding The cooperative module reader decoded the bytes as ELF before the container check, so gzip, xz, and zstd modules became malformed images. The compression check now returns the unsupported-container report first. Co-authored-by: morluto <morluto@users.noreply.github.com> * refactor(elf): classify each container once before reading it * fix(il2cpp): preserve admission order during cooperative linking * fix(elf): reuse section-name decoding in debug-link comparison (#12472) * style(elf): format updated section-reader test calls --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
527 lines
19 KiB
TypeScript
527 lines
19 KiB
TypeScript
import { basename } from "node:path";
|
|
import { producerLimitControl } from "../domain/producerResourceLimits.js";
|
|
import { RUST_BINARY_PROVIDER_IDENTITY } from "./RustBinaryProviderIdentity.js";
|
|
import {
|
|
projectSelectedArtifactFileFailure,
|
|
projectStableArtifactFailure,
|
|
stableArtifactInputFailure,
|
|
projectArtifactCloseFailure,
|
|
readerIntegrityFailure,
|
|
type StableArtifactSnapshot,
|
|
readStableArtifact,
|
|
artifactFilePrimaryFacts,
|
|
type ArtifactFilePrimaryFacts,
|
|
artifactFileCancellationCause,
|
|
assertArtifactReadActive,
|
|
yieldArtifactRead,
|
|
ArtifactResourceScope,
|
|
ArtifactReaderFailure,
|
|
} from "../resources/index.js";
|
|
import type { ExecutionOptions } from "../ports/AnalysisProvider.js";
|
|
import type { RustBinaryPort } from "../ports/rust/RustBinaryPort.js";
|
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import {
|
|
AnalysisOutputError,
|
|
AnalysisResourceConstraintError,
|
|
cancelledBy,
|
|
carriedReason,
|
|
} from "../domain/analysisErrorCore.js";
|
|
import {
|
|
RUST_AUDITABLE_FORMAT_VERSIONS,
|
|
rustBinarySchema,
|
|
rustcPartialCoverage,
|
|
type InspectRustBinaryInput,
|
|
type RustBinary,
|
|
} from "../domain/rust/rustBinary.js";
|
|
import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js";
|
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
import {
|
|
readRustBinaryImage,
|
|
readRustBinaryImageCooperative,
|
|
type RustBinaryImage,
|
|
} from "./RustBinaryImage.js";
|
|
import { requireSelectedNativeImage } from "../domain/apple/machoSliceSelection.js";
|
|
import {
|
|
RUST_AUDITABLE_FORMAT,
|
|
RUST_AUDITABLE_GRAPH_LIMIT,
|
|
} from "./RustAuditableReader.js";
|
|
import {
|
|
BinaryResourceFailure,
|
|
binaryResourceCeiling,
|
|
} from "../domain/binaryContainer.js";
|
|
import { MAX_WASM_SECTIONS, WASM_FORMAT } from "./RustWasmImage.js";
|
|
import {
|
|
isParseLimit,
|
|
parseFailureAnalysisError,
|
|
parseLimitConstraint,
|
|
} from "../domain/parseFailureAnalysisError.js";
|
|
|
|
import {
|
|
RUST_PRODUCER_DEFAULTS,
|
|
resolveRustProducerLimits,
|
|
rustProducerLimitsSchema,
|
|
type RustProducerLimits,
|
|
} from "../domain/rust/rustResourceLimits.js";
|
|
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
|
import { errorMessage } from "../kernel/errorMessage.js";
|
|
|
|
const OPERATION = "inspect_rust_binary";
|
|
|
|
/** Stable in-process dependency inspection without subprocesses, temporary files, or a Rust toolchain. */
|
|
export class RustBinaryProvider implements RustBinaryPort {
|
|
readonly identity = RUST_BINARY_PROVIDER_IDENTITY;
|
|
readonly #resources = new ArtifactResourceScope();
|
|
|
|
async close(): Promise<void> {
|
|
try {
|
|
await this.#resources.close();
|
|
} catch (cause: unknown) {
|
|
throw projectArtifactCloseFailure(
|
|
cause,
|
|
RUST_BINARY_PROVIDER_IDENTITY.id,
|
|
OPERATION,
|
|
);
|
|
}
|
|
}
|
|
|
|
/** Read one dependency section and any inferred rustc commit from the selected file. */
|
|
async inspect(
|
|
input: InspectRustBinaryInput,
|
|
options?: ExecutionOptions,
|
|
): Promise<Result<RustBinary, AnalysisError>> {
|
|
let snapshot: StableArtifactSnapshot | undefined;
|
|
const selectedLimits = rustProducerLimitsSchema.safeParse(
|
|
input.producer_limits === undefined ? {} : input.producer_limits,
|
|
);
|
|
if (!selectedLimits.success)
|
|
return err(
|
|
analysisInputErrorFromIssues(
|
|
OPERATION,
|
|
selectedLimits.error.issues.map((issue) => ({
|
|
...issue,
|
|
path: ["producer_limits", ...issue.path],
|
|
})),
|
|
input,
|
|
),
|
|
);
|
|
const limits = resolveRustProducerLimits(selectedLimits.data);
|
|
try {
|
|
return await this.#resources.run(async () => {
|
|
snapshot = await readStableArtifact(
|
|
input.path,
|
|
limits.input_bytes,
|
|
options?.signal,
|
|
undefined,
|
|
this.#resources,
|
|
);
|
|
assertArtifactReadActive(options?.signal);
|
|
const selected = requireSelectedNativeImage(
|
|
OPERATION,
|
|
input.path,
|
|
snapshot.bytes,
|
|
input.architecture,
|
|
);
|
|
const image = inFile(
|
|
options?.signal === undefined
|
|
? readRustBinaryImage(
|
|
selected.bytes,
|
|
input.max_rustc_hashes,
|
|
limits.output_bytes,
|
|
)
|
|
: await readRustBinaryImageCooperative(
|
|
selected.bytes,
|
|
input.max_rustc_hashes,
|
|
limits.output_bytes,
|
|
() => yieldArtifactRead(options.signal),
|
|
),
|
|
selected.fileOffset,
|
|
);
|
|
const report: RustBinary = {
|
|
format: image.format,
|
|
architecture: image.architecture,
|
|
bits: image.bits,
|
|
byte_order: image.byte_order,
|
|
auditable_metadata: image.auditable_metadata,
|
|
rustc_commit: image.rustc_commit,
|
|
artifact: {
|
|
path: input.path,
|
|
file_name: basename(input.path),
|
|
sha256: snapshot.sha256,
|
|
bytes: snapshot.bytes.length,
|
|
},
|
|
...(selected.selection === null
|
|
? {}
|
|
: { selected_slice: selected.selection }),
|
|
limitations: [
|
|
...limitationsFor(image),
|
|
`Selected producer_limits.input_bytes=${String(limits.input_bytes)} and output_bytes=${String(limits.output_bytes)} bytes; compressed/inflated dependency parser limits remain independent.`,
|
|
...selected.limitations,
|
|
],
|
|
};
|
|
retainCompilerPathsWithinReport(
|
|
report,
|
|
limits.output_bytes,
|
|
rustcLimitation(image.rustc_commit, image.format),
|
|
);
|
|
if (
|
|
Buffer.byteLength(JSON.stringify(report), "utf8") >
|
|
limits.output_bytes
|
|
)
|
|
throw outputLimit(input.path, limits.output_bytes);
|
|
const parsed = rustBinarySchema.safeParse(report);
|
|
if (!parsed.success)
|
|
throw new AnalysisOutputError(
|
|
OPERATION,
|
|
"Rust reader produced an invalid dependency report.",
|
|
{ cause: parsed.error },
|
|
);
|
|
assertArtifactReadActive(options?.signal);
|
|
return ok(parsed.data);
|
|
});
|
|
} catch (cause: unknown) {
|
|
return err(failureFor(cause, input.path, limits, snapshot));
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Locate image-relative section and rustc-path offsets in the selected file. */
|
|
const inFile = (image: RustBinaryImage, fileOffset: number): RustBinaryImage =>
|
|
fileOffset === 0
|
|
? image
|
|
: {
|
|
...image,
|
|
auditable_metadata:
|
|
image.auditable_metadata === null
|
|
? null
|
|
: {
|
|
...image.auditable_metadata,
|
|
file_offset: image.auditable_metadata.file_offset + fileOffset,
|
|
},
|
|
rustc_commit:
|
|
image.rustc_commit === null
|
|
? null
|
|
: {
|
|
...image.rustc_commit,
|
|
hashes: image.rustc_commit.hashes.map((entry) => ({
|
|
...entry,
|
|
file_offset: entry.file_offset + fileOffset,
|
|
})),
|
|
},
|
|
};
|
|
|
|
const outputLimit = (path: string, maxOutputBytes: number) =>
|
|
new AnalysisResourceConstraintError(
|
|
OPERATION,
|
|
"transport",
|
|
`Complete Rust metadata for ${path} exceeds the inline output budget; no partial success is returned.`,
|
|
{ maximum_output_bytes: maxOutputBytes },
|
|
{
|
|
retryable: false,
|
|
remediationAction: `Increase producer_limits.output_bytes above ${String(maxOutputBytes)} bytes on the next inspect_rust_binary call; no restart is required. Input, dependency parser and transport limits remain independent. Repeating the unchanged request does not raise admission.`,
|
|
limit: producerLimitControl(
|
|
"output_bytes",
|
|
maxOutputBytes,
|
|
RUST_PRODUCER_DEFAULTS.output_bytes,
|
|
),
|
|
},
|
|
);
|
|
|
|
/** Resource-guard guidance delivered with every Rust inspection report. */
|
|
const RUST_RESOURCE_GUARD_LIMITATION =
|
|
"Default input and complete-report admission are 256 MiB and 8 MiB; producer_limits.input_bytes/output_bytes select larger or smaller values for the next call without restart. Independent parser guards bound the compressed dependency stream to 1 MiB and inflated JSON to the smaller of 8 MiB and 64 times the consumed compressed-stream length. Report admission applies before package schema cloning, graph objects, or reverse-edge allocation.";
|
|
|
|
const limitationsFor = (
|
|
image: ReturnType<typeof readRustBinaryImage>,
|
|
): string[] => [
|
|
"Embedded dependency metadata is file content. It does not authenticate package names, versions, sources, or the compiler that produced the binary.",
|
|
`Only the .dep-v0 dependency section and compiler path strings in ${compilerPathSource(image.format)} are inspected. Functions, types, and runtime behavior are not recovered.`,
|
|
...(image.format === "wasm"
|
|
? [
|
|
`WebAssembly declares no container word size, so bits is null. Memory address types were not inspected. At most ${MAX_WASM_SECTIONS} section payloads are examined.`,
|
|
]
|
|
: []),
|
|
RUST_RESOURCE_GUARD_LIMITATION,
|
|
...(image.section_names_limitation === undefined
|
|
? []
|
|
: [image.section_names_limitation]),
|
|
...(image.auditable_metadata === null &&
|
|
image.section_names_limitation === undefined
|
|
? [
|
|
"No .dep-v0 section was found. Absence of .dep-v0 does not mean the binary has no dependencies.",
|
|
]
|
|
: []),
|
|
...(image.auditable_metadata === null &&
|
|
image.section_names_limitation !== undefined
|
|
? [
|
|
"The presence of .dep-v0 could not be determined because ELF section names are unavailable.",
|
|
]
|
|
: []),
|
|
...unknownFormatLimitation(image.auditable_metadata?.format_version),
|
|
...(image.auditable_metadata?.packages.some((pkg) => pkg.kind === null)
|
|
? [
|
|
"An omitted package kind is left null. The embedded format treats an omitted kind as runtime, and that default was not stored in the section.",
|
|
]
|
|
: []),
|
|
...(image.auditable_metadata !== null &&
|
|
image.auditable_metadata.cyclic_dependency_indices.length > 0
|
|
? [
|
|
"Dependency indices contain a cycle. The cycle is reported and was not traversed.",
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const unknownFormatLimitation = (
|
|
format: number | null | undefined,
|
|
): string[] => {
|
|
if (format === null || format === undefined) return [];
|
|
let preceding = 0;
|
|
for (const known of RUST_AUDITABLE_FORMAT_VERSIONS) {
|
|
if (known === format) return [];
|
|
if (known < format) preceding = known;
|
|
}
|
|
return [
|
|
`cargo-auditable format revision ${format} is unknown. Its schema directs readers to interpret it using the highest known preceding revision (${preceding}); this specific revision has not been independently verified.`,
|
|
];
|
|
};
|
|
|
|
/** rustc keeps constant path strings in native read-only data or WebAssembly data segments. */
|
|
const compilerPathSource = (format: RustBinary["format"]): string =>
|
|
format === "wasm" ? "the WebAssembly data section" : "read-only data";
|
|
|
|
const rustcLimitation = (
|
|
commit: ReturnType<typeof readRustBinaryImage>["rustc_commit"],
|
|
format: RustBinary["format"],
|
|
): string[] => {
|
|
const source = compilerPathSource(format);
|
|
if (commit === null)
|
|
return [
|
|
`No /rustc/<40-hex>/ path was found in ${source}, so a rustc commit hash is unknown.`,
|
|
];
|
|
if (commit.coverage?.reason === "report_bytes")
|
|
return [
|
|
"Compiler-path retention exhausted the complete-report byte allowance; retained hashes are a prefix and compiler coverage is partial. Dependency observations are independent. Raise the control in rustc_commit.coverage.limit on the next call to raise report admission; no restart is required. Increasing max_rustc_hashes alone does not raise it.",
|
|
];
|
|
if (commit.coverage?.status === "partial")
|
|
return [
|
|
`Compiler-path retention reached max_rustc_hashes=${String(commit.coverage.effective_limit)}; the listed hashes are a prefix and compiler coverage is partial. Raise the control in rustc_commit.coverage.limit on the next call to retain more paths; no restart is required. Dependency observations are independent. The complete-report byte allowance still applies.`,
|
|
];
|
|
if (commit.hashes.length === 1)
|
|
return [
|
|
`The rustc commit hash is inferred from a /rustc/<40-hex>/ path in ${source}. It does not by itself prove which compiler produced the binary.`,
|
|
];
|
|
return [
|
|
`More than one /rustc/<40-hex>/ path was found in ${source}, so a single rustc commit is unknown.`,
|
|
];
|
|
};
|
|
|
|
/**
|
|
* Optional inferred paths never displace independently observed dependency
|
|
* facts. The compiler guidance describes the retained result: the reader's
|
|
* guidance when it fits; the reader's record and control without that
|
|
* guidance (which restates rustc_commit.coverage) when only the guidance
|
|
* does not fit; otherwise the trimming guidance, which names its control
|
|
* directly because no compiler record may survive. Byte trimming is reported
|
|
* only when it removes a path.
|
|
*/
|
|
const retainCompilerPathsWithinReport = (
|
|
report: RustBinary,
|
|
maxOutputBytes: number,
|
|
compilerGuidance: readonly string[],
|
|
): void => {
|
|
const commit = report.rustc_commit;
|
|
const withGuidance = [...report.limitations, ...compilerGuidance];
|
|
if (
|
|
commit === null ||
|
|
Buffer.byteLength(
|
|
JSON.stringify({ ...report, limitations: withGuidance }),
|
|
) <= maxOutputBytes
|
|
) {
|
|
report.limitations = withGuidance;
|
|
return;
|
|
}
|
|
if (Buffer.byteLength(JSON.stringify(report)) <= maxOutputBytes) return;
|
|
const limitation =
|
|
"Compiler paths were omitted to preserve dependency facts within the complete-report byte allowance; compiler-path coverage is partial. Increase producer_limits.output_bytes on the next call; no restart is required. Increasing max_rustc_hashes alone does not raise this allowance.";
|
|
const baseline = {
|
|
...report,
|
|
rustc_commit: null,
|
|
limitations: [...report.limitations, limitation],
|
|
};
|
|
const empty = {
|
|
...commit,
|
|
hashes: [],
|
|
coverage: rustcPartialCoverage("report_bytes", maxOutputBytes),
|
|
};
|
|
const available =
|
|
maxOutputBytes -
|
|
Buffer.byteLength(JSON.stringify({ ...baseline, rustc_commit: empty }));
|
|
let retainedBytes = 0;
|
|
let count = 0;
|
|
// The complete record does not fit, so trimming removes at least one path
|
|
// and the byte coverage it records stays true.
|
|
for (const hash of commit.hashes.slice(0, -1)) {
|
|
const bytes =
|
|
Buffer.byteLength(JSON.stringify(hash)) + (count === 0 ? 0 : 1);
|
|
if (bytes > available - retainedBytes) break;
|
|
retainedBytes += bytes;
|
|
count++;
|
|
}
|
|
if (count === 0) {
|
|
// The control stays recorded although no compiler record survives.
|
|
report.rustc_commit = null;
|
|
if (empty.coverage.limit !== undefined)
|
|
report.rustc_commit_omission = {
|
|
reason: "report_bytes",
|
|
limit: empty.coverage.limit,
|
|
};
|
|
} else
|
|
report.rustc_commit = { ...empty, hashes: commit.hashes.slice(0, count) };
|
|
report.limitations = baseline.limitations;
|
|
};
|
|
|
|
const failureForPrimary = (
|
|
facts: ArtifactFilePrimaryFacts,
|
|
path: string,
|
|
limits: RustProducerLimits,
|
|
): AnalysisError => {
|
|
const { cause, origin } = facts;
|
|
if (origin === "owned-or-classified" && cause instanceof AnalysisError)
|
|
return cause;
|
|
if (cause instanceof BinaryResourceFailure)
|
|
return parseLimitConstraint(OPERATION, "memory", cause, {
|
|
path,
|
|
legacyMaximumKey: "maximum_bytes",
|
|
...fixedAllowanceOptions(
|
|
"This native container parser allowance",
|
|
"parser",
|
|
binaryResourceCeiling(cause),
|
|
),
|
|
});
|
|
if (isParseLimit(cause, RUST_AUDITABLE_FORMAT)) {
|
|
const { name, maximum } = cause.failure.limit;
|
|
if (name === RUST_AUDITABLE_GRAPH_LIMIT)
|
|
return parseLimitConstraint(OPERATION, "transport", cause, {
|
|
path,
|
|
legacyMaximumKey: "maximum_output_bytes",
|
|
retryable: false,
|
|
remediationAction: `Increase producer_limits.output_bytes above ${String(maximum)} bytes on the next call; no restart is required. Compressed/inflated dependency parser and transport limits remain independent.`,
|
|
limit: producerLimitControl(
|
|
"output_bytes",
|
|
maximum,
|
|
RUST_PRODUCER_DEFAULTS.output_bytes,
|
|
),
|
|
});
|
|
return parseLimitConstraint(OPERATION, "memory", cause, {
|
|
path,
|
|
legacyMaximumKey: "maximum_bytes",
|
|
...fixedAllowanceOptions(
|
|
"This Rust dependency parser allowance",
|
|
"parser",
|
|
{
|
|
limit: maximum,
|
|
unit: "bytes",
|
|
},
|
|
),
|
|
});
|
|
}
|
|
if (isParseLimit(cause, WASM_FORMAT))
|
|
return parseLimitConstraint(OPERATION, "cpu", cause, {
|
|
path,
|
|
...fixedAllowanceOptions(
|
|
"The WebAssembly section-walk allowance",
|
|
"work",
|
|
{ limit: cause.failure.limit.maximum, unit: "sections" },
|
|
),
|
|
});
|
|
return (
|
|
parseFailureAnalysisError(OPERATION, path, cause) ??
|
|
artifactFailure(facts, path, limits)
|
|
);
|
|
};
|
|
|
|
const failureFor = (
|
|
cause: unknown,
|
|
path: string,
|
|
limits: RustProducerLimits,
|
|
snapshot?: StableArtifactSnapshot,
|
|
): AnalysisError => {
|
|
const primary = failureForPrimary(
|
|
artifactFilePrimaryFacts(cause),
|
|
path,
|
|
limits,
|
|
);
|
|
return projectStableArtifactFailure(
|
|
cause,
|
|
primary,
|
|
path,
|
|
RUST_BINARY_PROVIDER_IDENTITY.id,
|
|
OPERATION,
|
|
snapshot,
|
|
);
|
|
};
|
|
|
|
const artifactFailure = (
|
|
facts: ArtifactFilePrimaryFacts,
|
|
path: string,
|
|
limits: RustProducerLimits,
|
|
): AnalysisError => {
|
|
const { cause, origin } = facts;
|
|
if (
|
|
origin === "owned-or-classified" &&
|
|
cause instanceof ArtifactReaderFailure
|
|
)
|
|
return artifactReaderFailure(cause, path, limits);
|
|
const fileFailure = projectSelectedArtifactFileFailure(
|
|
cause,
|
|
OPERATION,
|
|
path,
|
|
"artifact",
|
|
);
|
|
if (fileFailure !== undefined) return fileFailure;
|
|
return new ProviderAdapterError(RUST_BINARY_PROVIDER_IDENTITY.id, OPERATION, {
|
|
cause,
|
|
diagnostics: {
|
|
path,
|
|
reason: errorMessage(cause),
|
|
},
|
|
});
|
|
};
|
|
|
|
const artifactReaderFailure = (
|
|
cause: ArtifactReaderFailure,
|
|
path: string,
|
|
limits: RustProducerLimits,
|
|
): AnalysisError => {
|
|
if (cause.reason === "integrity")
|
|
return readerIntegrityFailure(OPERATION, path, cause);
|
|
if (cause.reason === "cancelled")
|
|
return cancelledBy(
|
|
OPERATION,
|
|
carriedReason(artifactFileCancellationCause(cause)),
|
|
);
|
|
if (cause.reason === "limit")
|
|
return new AnalysisResourceConstraintError(
|
|
OPERATION,
|
|
"file-size",
|
|
cause.message,
|
|
{ maximum_input_bytes: limits.input_bytes },
|
|
{
|
|
cause,
|
|
retryable: false,
|
|
remediationAction: `Increase producer_limits.input_bytes above ${String(limits.input_bytes)} bytes on the next inspect_rust_binary call; no restart is required. Select the same complete artifact, without truncating its bytes. Report, dependency parser and host memory limits remain independent.`,
|
|
limit: producerLimitControl(
|
|
"input_bytes",
|
|
limits.input_bytes,
|
|
RUST_PRODUCER_DEFAULTS.input_bytes,
|
|
),
|
|
},
|
|
);
|
|
if (cause.reason === "path")
|
|
return stableArtifactInputFailure(cause, OPERATION);
|
|
return new ProviderAdapterError(RUST_BINARY_PROVIDER_IDENTITY.id, OPERATION, {
|
|
cause,
|
|
diagnostics: { path, reason: cause.message },
|
|
});
|
|
};
|