mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
feat(artifacts): require every integrity reader failure to name its check (#11505)
ArtifactReaderFailure overloads require integrityCheck for a literal "integrity" reason and an explicit (possibly undefined) check for a rebuild whose reason is not a literal; primaryFacts always carries it. The .NET bundle reader uses assertProducedEntry, and the PyInstaller cookie probe and owned lease cleanup rewrap keep the check they previously dropped.
This commit is contained in:
1 parent
c1546be70d
commit
6fa58b0ec8
24 files changed
+152
-67
No files matched your search
@@ -480,6 +480,7 @@ it.each([
|
||||
new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"Extracted content disagrees with inventory",
|
||||
{ integrityCheck: "container-identity" },
|
||||
),
|
||||
},
|
||||
] as const)(
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
type PyInstallerCookie,
|
||||
type PyInstallerCookieObservation,
|
||||
} from "./pyinstaller/CArchiveLayout.js";
|
||||
import { pyInstallerReaderFailure } from "./pyinstaller/PyInstallerFailure.js";
|
||||
|
||||
/** Completed observations and explicit recognition limits; null alone is examined absence. */
|
||||
export interface ArtifactEmbeddedFormatProbeFacts {
|
||||
@@ -138,8 +139,7 @@ export class ArtifactEmbeddedFormatProbes {
|
||||
this.signal,
|
||||
);
|
||||
abortIfNeeded(this.signal);
|
||||
if (!found.ok)
|
||||
throw new ArtifactReaderFailure(found.error.reason, found.error.message);
|
||||
if (!found.ok) throw pyInstallerReaderFailure(found.error);
|
||||
this.#facts = { ...this.#facts, pyInstaller: found.value };
|
||||
return found.value.state === "located" ? found.value.cookie : undefined;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import type { StableRegularFileDescriptor } from "../filesystem/RegularFile.js";
|
||||
import {
|
||||
ArtifactResourceScope,
|
||||
ArtifactReaderFailure,
|
||||
assertProducedEntry,
|
||||
copyArtifactEntry,
|
||||
sameArtifactEntry,
|
||||
type ArtifactEntry,
|
||||
type ArtifactReader,
|
||||
type ArtifactTraversalOptions,
|
||||
@@ -146,11 +146,11 @@ export class DotnetBundleArtifactReader implements ArtifactReader {
|
||||
const source = await this.#source.readSelectedPath(signal);
|
||||
this.#assertOpen(signal);
|
||||
const selected = this.#entries.get(entry.adapterKey);
|
||||
if (selected === undefined || !sameArtifactEntry(entry, selected.entry))
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"Selected .NET bundle entry differs from its observed manifest",
|
||||
);
|
||||
assertProducedEntry(
|
||||
entry,
|
||||
selected?.entry,
|
||||
"Selected .NET bundle entry differs from its observed manifest",
|
||||
);
|
||||
const stream = Readable.from(
|
||||
this.#readMember(source, selected.file, signal),
|
||||
{ objectMode: false },
|
||||
|
||||
@@ -545,7 +545,9 @@ it("preserves a final validation failure when cancellation overlaps it", async (
|
||||
);
|
||||
const controller = new AbortController();
|
||||
const finalValidation = phaseGate();
|
||||
const failure = new ArtifactReaderFailure("integrity", "carrier changed");
|
||||
const failure = new ArtifactReaderFailure("integrity", "carrier changed", {
|
||||
integrityCheck: "container-identity",
|
||||
});
|
||||
const read = ArtifactFileSource.prototype.read;
|
||||
const readChunks = fileChunks.readFileHandleChunks;
|
||||
let owner: ArtifactFileSource | undefined;
|
||||
|
||||
@@ -98,9 +98,8 @@ class NativeDmgCommandFailure extends ArtifactReaderFailure {
|
||||
? {}
|
||||
: { cancellation: options.cancellation }),
|
||||
// Only hdiutil verify classifies a DMG failure as integrity.
|
||||
...(failure.reason === "integrity"
|
||||
? { integrityCheck: "image-checksum" as const }
|
||||
: {}),
|
||||
integrityCheck:
|
||||
failure.reason === "integrity" ? "image-checksum" : undefined,
|
||||
});
|
||||
this.processNotStarted = options?.processNotStarted ?? false;
|
||||
this.verifyDiagnostic = failure.verifyDiagnostic;
|
||||
|
||||
@@ -51,7 +51,7 @@ import {
|
||||
type CarrierPathDialect,
|
||||
} from "./pyinstaller/CArchiveMembers.js";
|
||||
import { readPyzArchive } from "./pyinstaller/PyzArchive.js";
|
||||
import type { PyInstallerFailure } from "./pyinstaller/PyInstallerFailure.js";
|
||||
import { pyInstallerReaderFailure as failure } from "./pyinstaller/PyInstallerFailure.js";
|
||||
import { readPyInstallerBytes } from "./pyinstaller/PyInstallerBytes.js";
|
||||
|
||||
const MAX_PARSED_FACT_BYTES = 32 * 1024 * 1024;
|
||||
@@ -687,12 +687,3 @@ export class PyInstallerArtifactReader implements ArtifactReader {
|
||||
state.charged += bytes;
|
||||
}
|
||||
}
|
||||
|
||||
const failure = (error: PyInstallerFailure): ArtifactReaderFailure =>
|
||||
new ArtifactReaderFailure(
|
||||
error.reason,
|
||||
error.message,
|
||||
error.reason === "integrity"
|
||||
? { integrityCheck: error.integrityCheck }
|
||||
: undefined,
|
||||
);
|
||||
@@ -680,6 +680,7 @@ describe("ReleaseExposureReader limits", () => {
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
`Artifact changed during inventory: ${target}`,
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
};
|
||||
const reader = new ReleaseExposureReader();
|
||||
|
||||
@@ -109,6 +109,7 @@ it.each([false, true])(
|
||||
const failure = new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"controlled physical archive refusal",
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
const open = vi
|
||||
.spyOn(DirectoryArtifactReader.prototype, "open")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ArtifactIntegrityCheck } from "../../domain/artifactOperationError.js";
|
||||
import { ArtifactReaderFailure } from "../../resources/index.js";
|
||||
|
||||
/** Typed failure from a pure PyInstaller parser before the reader adapts it. */
|
||||
export type PyInstallerFailure =
|
||||
@@ -9,6 +10,16 @@ export type PyInstallerFailure =
|
||||
readonly integrityCheck: ArtifactIntegrityCheck;
|
||||
};
|
||||
|
||||
/** Adapt a parser failure, keeping the integrity check it names. */
|
||||
export const pyInstallerReaderFailure = (
|
||||
error: PyInstallerFailure,
|
||||
): ArtifactReaderFailure =>
|
||||
error.reason === "integrity"
|
||||
? new ArtifactReaderFailure(error.reason, error.message, {
|
||||
integrityCheck: error.integrityCheck,
|
||||
})
|
||||
: new ArtifactReaderFailure(error.reason, error.message);
|
||||
|
||||
export const pyInstallerFailure = (
|
||||
reason: "format" | "limit",
|
||||
message: string,
|
||||
|
||||
@@ -255,6 +255,7 @@ it.each(["before open", "during read"])(
|
||||
const cause = new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
`Artifact changed ${stage}: ${path}`,
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
const error = historicalCaptureFailure(input, cause, "capture-read");
|
||||
const projected = projectAnalysisError(error);
|
||||
@@ -409,7 +410,9 @@ it("preserves the exact cancellation reason and an earlier reader failure", () =
|
||||
|
||||
const changed = historicalCaptureFailure(
|
||||
input,
|
||||
new ArtifactReaderFailure("integrity", "Observed changed capture"),
|
||||
new ArtifactReaderFailure("integrity", "Observed changed capture", {
|
||||
integrityCheck: "container-identity",
|
||||
}),
|
||||
"capture-read",
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
|
||||
@@ -28,7 +28,9 @@ it.each([new RangeError("unexpected range"), new TypeError("unexpected type")])(
|
||||
it.each(["integrity", "path"] as const)(
|
||||
"reports a %s source-read refusal as a change to the bound target, not a provider failure",
|
||||
(reason) => {
|
||||
const cause = new ArtifactReaderFailure(reason, "source boundary refused");
|
||||
const cause = new ArtifactReaderFailure(reason, "source boundary refused", {
|
||||
integrityCheck: reason === "integrity" ? "container-identity" : undefined,
|
||||
});
|
||||
expect(appleDispatchMetadataFailure(cause, "/selected")._tag).toBe(
|
||||
"AnalysisArtifactChangedError",
|
||||
);
|
||||
|
||||
@@ -44,7 +44,7 @@ export class NativeMachoSourceVerificationFailure extends ArtifactReaderFailure
|
||||
? {}
|
||||
: { cancellation: verificationCause.cancellation }),
|
||||
}
|
||||
: {}),
|
||||
: { integrityCheck: undefined }),
|
||||
},
|
||||
verificationCause instanceof ArtifactReaderFailure
|
||||
? verificationCause.details
|
||||
|
||||
@@ -65,6 +65,7 @@ export class OwnedLeaseCleanupFailure extends ArtifactReaderFailure {
|
||||
super(failure.reason, failure.message, {
|
||||
cause: primary,
|
||||
cleanup: failure.cleanup,
|
||||
integrityCheck: failure.integrityCheck,
|
||||
});
|
||||
this.cleanupLeases = failure.cleanupLeases;
|
||||
}
|
||||
|
||||
@@ -56,3 +56,19 @@ it.each([
|
||||
expect(second.cause).toBe(first);
|
||||
},
|
||||
);
|
||||
|
||||
it("requires an integrity failure to name its check, including when rebuilt", () => {
|
||||
// @ts-expect-error An integrity failure names the check that failed.
|
||||
void new ArtifactReaderFailure("integrity", "unnamed integrity failure");
|
||||
const primary = new ArtifactReaderFailure("integrity", "carrier changed", {
|
||||
integrityCheck: "container-identity",
|
||||
});
|
||||
const rebuilt = new ArtifactReaderFailure(primary.reason, primary.message, {
|
||||
cause: primary,
|
||||
...primary.primaryFacts(),
|
||||
});
|
||||
expect(rebuilt.integrityCheck).toBe("container-identity");
|
||||
const reason: ArtifactReaderFailure["reason"] = primary.reason;
|
||||
// @ts-expect-error A rebuild with a non-literal reason carries the check.
|
||||
void new ArtifactReaderFailure(reason, "rebuilt without its check");
|
||||
});
|
||||
@@ -42,7 +42,7 @@ export interface ArtifactReaderFailureOptions extends ErrorOptions {
|
||||
readonly admission?: ArtifactAdmissionLimit;
|
||||
readonly readerLimit?: ArtifactReaderLimitFact;
|
||||
/** For an `integrity` failure, the check that failed, when the reader names it. */
|
||||
readonly integrityCheck?: ArtifactIntegrityCheck;
|
||||
readonly integrityCheck?: ArtifactIntegrityCheck | undefined;
|
||||
}
|
||||
|
||||
/** Archive-neutral entry metadata. Reader adapters never choose output paths. */
|
||||
@@ -268,6 +268,16 @@ export type CleanupFailedRead = ArtifactReaderFailure & {
|
||||
readonly cleanup: AnalysisCleanupObservation;
|
||||
};
|
||||
|
||||
/** Why an artifact reader failed. */
|
||||
export type ArtifactReaderFailureReason =
|
||||
| "cancelled"
|
||||
| "format"
|
||||
| "integrity"
|
||||
| "io"
|
||||
| "limit"
|
||||
| "path"
|
||||
| "unavailable";
|
||||
|
||||
export class ArtifactReaderFailure extends Error {
|
||||
readonly userMessage: string | undefined;
|
||||
readonly resolvedPath: string | undefined;
|
||||
@@ -282,15 +292,35 @@ export class ArtifactReaderFailure extends Error {
|
||||
readonly readerLimit: ArtifactReaderLimitFact | undefined;
|
||||
readonly integrityCheck: ArtifactIntegrityCheck | undefined;
|
||||
|
||||
/** An `integrity` failure names the check that failed. */
|
||||
constructor(
|
||||
readonly reason:
|
||||
| "cancelled"
|
||||
| "format"
|
||||
| "integrity"
|
||||
| "io"
|
||||
| "limit"
|
||||
| "path"
|
||||
| "unavailable",
|
||||
reason: "integrity",
|
||||
message: string,
|
||||
options: ArtifactReaderFailureOptions & {
|
||||
readonly integrityCheck: ArtifactIntegrityCheck;
|
||||
},
|
||||
details?: ArtifactIntegrityDetails,
|
||||
);
|
||||
constructor(
|
||||
reason: Exclude<ArtifactReaderFailureReason, "integrity">,
|
||||
message: string,
|
||||
options?: ArtifactReaderFailureOptions,
|
||||
details?: ArtifactIntegrityDetails,
|
||||
);
|
||||
/**
|
||||
* A rebuild whose reason is not a literal carries the check explicitly, as
|
||||
* {@link primaryFacts} does, so a rewrapped integrity failure keeps it.
|
||||
*/
|
||||
constructor(
|
||||
reason: ArtifactReaderFailureReason,
|
||||
message: string,
|
||||
options: ArtifactReaderFailureOptions & {
|
||||
readonly integrityCheck: ArtifactIntegrityCheck | undefined;
|
||||
},
|
||||
details?: ArtifactIntegrityDetails,
|
||||
);
|
||||
constructor(
|
||||
readonly reason: ArtifactReaderFailureReason,
|
||||
message: string,
|
||||
options?: ArtifactReaderFailureOptions,
|
||||
readonly details?: ArtifactIntegrityDetails,
|
||||
@@ -319,13 +349,8 @@ export class ArtifactReaderFailure extends Error {
|
||||
*/
|
||||
primaryFacts(): Pick<
|
||||
ArtifactReaderFailureOptions,
|
||||
| "userMessage"
|
||||
| "resolvedPath"
|
||||
| "boundary"
|
||||
| "admission"
|
||||
| "readerLimit"
|
||||
| "integrityCheck"
|
||||
> {
|
||||
"userMessage" | "resolvedPath" | "boundary" | "admission" | "readerLimit"
|
||||
> & { readonly integrityCheck: ArtifactIntegrityCheck | undefined } {
|
||||
return {
|
||||
...(this.userMessage === undefined
|
||||
? {}
|
||||
@@ -338,9 +363,7 @@ export class ArtifactReaderFailure extends Error {
|
||||
...(this.readerLimit === undefined
|
||||
? {}
|
||||
: { readerLimit: this.readerLimit }),
|
||||
...(this.integrityCheck === undefined
|
||||
? {}
|
||||
: { integrityCheck: this.integrityCheck }),
|
||||
integrityCheck: this.integrityCheck,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@ import type { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
|
||||
import type { OwnedDirectoryHandle } from "../filesystem/OwnedDirectoryHandle.js";
|
||||
import type { OwnedStagedOutput } from "../filesystem/OwnedStagedOutput.js";
|
||||
|
||||
import type { ArtifactReader } from "./ArtifactReader.js";
|
||||
import type {
|
||||
ArtifactReader,
|
||||
ArtifactReaderFailureOptions,
|
||||
} from "./ArtifactReader.js";
|
||||
import {
|
||||
ArtifactReaderFailure,
|
||||
artifactPrimaryCleanupLeases,
|
||||
@@ -89,7 +92,7 @@ export class ArtifactResourceRetryFailure extends ArtifactReaderFailure {
|
||||
readonly lease: AnalysisCleanupLease;
|
||||
}[],
|
||||
message: string,
|
||||
options: ConstructorParameters<typeof ArtifactReaderFailure>[2],
|
||||
options?: ArtifactReaderFailureOptions,
|
||||
) {
|
||||
super("unavailable", message, options);
|
||||
this.failedOwners = failures.map(({ owner }) => owner);
|
||||
|
||||
@@ -776,8 +776,9 @@ const assertContainedDirectory = async (
|
||||
throw new ArtifactReaderFailure(
|
||||
failureReason,
|
||||
"Directory traversal escaped or changed its artifact root",
|
||||
failureReason === "integrity"
|
||||
? { integrityCheck: "container-identity" }
|
||||
: undefined,
|
||||
{
|
||||
integrityCheck:
|
||||
failureReason === "integrity" ? "container-identity" : undefined,
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -268,9 +268,10 @@ const verifyInactiveJournal = async (
|
||||
phase === "initial"
|
||||
? `Rollback journal may require recovery: ${path}. Supply a clean offline snapshot; only empty journals or a fully zeroed header are supported.`
|
||||
: `Rollback journal became active or malformed during database acquisition: ${path}`,
|
||||
phase === "initial"
|
||||
? undefined
|
||||
: { integrityCheck: "container-identity" },
|
||||
{
|
||||
integrityCheck:
|
||||
phase === "initial" ? undefined : "container-identity",
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -132,6 +132,7 @@ it("unwinds every nested traversal and preserves its primary failure", async ()
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"primary nested member failure",
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
},
|
||||
async return() {
|
||||
|
||||
@@ -164,6 +164,7 @@ it.each(["decode_interface_builder", "inspect_keyed_archive"] as const)(
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"controlled Interface Builder source change",
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
})
|
||||
: undefined;
|
||||
|
||||
@@ -483,7 +483,16 @@ it("rejects replacement, forged entry metadata and cancellation without losing c
|
||||
const entry = entries[0]!;
|
||||
await expect(
|
||||
reader.open({ ...entry, declaredSize: 1 }),
|
||||
).rejects.toMatchObject({ reason: "integrity" });
|
||||
).rejects.toMatchObject({
|
||||
reason: "integrity",
|
||||
integrityCheck: "entry-metadata",
|
||||
});
|
||||
await expect(
|
||||
reader.open({ ...entry, adapterKey: "foreign" }),
|
||||
).rejects.toMatchObject({
|
||||
reason: "integrity",
|
||||
integrityCheck: "foreign-entry",
|
||||
});
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
await expect(reader.open(entry, controller.signal)).rejects.toMatchObject({
|
||||
|
||||
@@ -784,6 +784,10 @@ describe("bounded Interface Builder archive decoding", () => {
|
||||
const failure = new ArtifactReaderFailure(
|
||||
reason,
|
||||
"source acquisition failed",
|
||||
{
|
||||
integrityCheck:
|
||||
reason === "integrity" ? "container-identity" : undefined,
|
||||
},
|
||||
);
|
||||
const open = vi
|
||||
.spyOn(DirectoryArtifactReader.prototype, "open")
|
||||
|
||||
@@ -61,6 +61,27 @@ const fileOutcomeControls = (["signal", "capture"] as const).flatMap((kind) =>
|
||||
|
||||
type FileOutcomeControl = (typeof fileOutcomeControls)[number];
|
||||
|
||||
/** The physical read failure a control injects, with the facts production names. */
|
||||
const physicalFailure = (failure: FileOutcomeControl["failure"]): Error =>
|
||||
failure === "denied"
|
||||
? Object.assign(new Error("controlled read denial"), { code: "EACCES" })
|
||||
: failure === "format"
|
||||
? new ArtifactReaderFailure("format", "controlled physical file failure")
|
||||
: failure === "limit"
|
||||
? // The stable reader names the bound it refused, as production does.
|
||||
new ArtifactReaderFailure(
|
||||
"limit",
|
||||
"controlled physical file failure",
|
||||
{
|
||||
boundary: "file-size",
|
||||
},
|
||||
)
|
||||
: new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"controlled physical file failure",
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
|
||||
const createFileOutcomeFixture = async ({
|
||||
kind,
|
||||
stage,
|
||||
@@ -81,19 +102,7 @@ const createFileOutcomeFixture = async ({
|
||||
: "if(process.argv.includes('--version')) console.log('TShark (Wireshark) 4.6.9 (fixture)'); else console.log('[]');",
|
||||
{ mode: 0o700 },
|
||||
);
|
||||
const physical =
|
||||
failure === "denied"
|
||||
? Object.assign(new Error("controlled read denial"), { code: "EACCES" })
|
||||
: new ArtifactReaderFailure(
|
||||
failure === "format"
|
||||
? "format"
|
||||
: failure === "limit"
|
||||
? "limit"
|
||||
: "integrity",
|
||||
"controlled physical file failure",
|
||||
// The stable reader names the bound it refused, as production does.
|
||||
failure === "limit" ? { boundary: "file-size" } : undefined,
|
||||
);
|
||||
const physical = physicalFailure(failure);
|
||||
const selectedPath =
|
||||
resource === "limiter"
|
||||
? limiter
|
||||
|
||||
@@ -388,7 +388,9 @@ it.each(
|
||||
[
|
||||
name,
|
||||
makeProvider,
|
||||
new ArtifactReaderFailure("integrity", "source replacement"),
|
||||
new ArtifactReaderFailure("integrity", "source replacement", {
|
||||
integrityCheck: "container-identity",
|
||||
}),
|
||||
AnalysisArtifactChangedError,
|
||||
] as const,
|
||||
[
|
||||
@@ -441,6 +443,7 @@ it.each(staticProviders)(
|
||||
const primary = new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"controlled source replacement",
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
fault.readFailure = { cause: primary };
|
||||
const controller = new AbortController();
|
||||
@@ -479,6 +482,7 @@ it("clears the Python pyc cleanup flag once a retained descriptor closes", async
|
||||
const primary = new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"controlled source replacement",
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
fault.readFailure = { cause: primary };
|
||||
try {
|
||||
@@ -1176,6 +1180,7 @@ it.each(fileFailureProviders)(
|
||||
const primary = new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"original source replacement",
|
||||
{ integrityCheck: "container-identity" },
|
||||
);
|
||||
try {
|
||||
const nested = await scope
|
||||
|
||||
Reference in new issue
Block a user