fix(artifacts): complete prefix reads and share ZIP format admission
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { readFileHandlePrefix } from "../filesystem/readFileHandlePrefix.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { Readable } from "node:stream";
|
||||
import {
|
||||
@@ -42,15 +43,13 @@ export class InesArtifactReader implements ArtifactReader {
|
||||
async *entries(signal?: AbortSignal): AsyncIterable<ArtifactEntry> {
|
||||
abortIfNeeded(signal);
|
||||
await this.#verifySource(signal);
|
||||
const prefix = Buffer.alloc(16);
|
||||
const { bytesRead } = await this.source.handle.read(prefix, 0, 16, 0);
|
||||
const prefix = await readFileHandlePrefix(this.source.handle, 16, () =>
|
||||
abortIfNeeded(signal),
|
||||
);
|
||||
abortIfNeeded(signal);
|
||||
// Concurrent source changes take precedence over malformed header diagnostics.
|
||||
await this.#verifySource(signal);
|
||||
const parsed = parseInesLayout(
|
||||
prefix.subarray(0, bytesRead),
|
||||
this.source.initial.size,
|
||||
);
|
||||
const parsed = parseInesLayout(prefix, this.source.initial.size);
|
||||
if (!parsed.ok) throw new ArtifactReaderFailure("format", parsed.error);
|
||||
this.#layout = parsed.value;
|
||||
this.#entries.clear();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isZipPackageFormat } from "../../domain/zipPackageFormat.js";
|
||||
import { lstat, realpath } from "node:fs/promises";
|
||||
|
||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
||||
@@ -410,13 +411,6 @@ interface ExtractionInventory {
|
||||
readonly integrityContradictions: readonly IntegrityContradiction[];
|
||||
}
|
||||
|
||||
const ZIP_FORMATS = ["ipa", "apk", "msix", "appx", "zip"] as const;
|
||||
|
||||
const isZipFormat = (
|
||||
format: BinaryTarget["format"] | ArtifactGraphManifest["root_format"],
|
||||
): format is (typeof ZIP_FORMATS)[number] =>
|
||||
(ZIP_FORMATS as readonly string[]).includes(format);
|
||||
|
||||
/**
|
||||
* Refuse a format without an extraction reader before inventory work starts.
|
||||
* The target kind, not the host, is unsupported by extraction. The error keeps
|
||||
@@ -433,7 +427,7 @@ const requireExtractableFormat = async (
|
||||
format !== "asar" &&
|
||||
format !== "ines" &&
|
||||
!isMachOFormat(format) &&
|
||||
!isZipFormat(format)
|
||||
!isZipPackageFormat(format)
|
||||
)
|
||||
throw new AnalysisUnsupportedTargetError(
|
||||
"extract_artifact",
|
||||
@@ -498,7 +492,7 @@ const createReader = async (
|
||||
}
|
||||
if (format === "directory") return new DirectoryArtifactReader(path);
|
||||
if (format === "asar") return new AsarArtifactReader(path);
|
||||
if (isZipFormat(format)) return new ZipArtifactReader(path, format);
|
||||
if (isZipPackageFormat(format)) return new ZipArtifactReader(path, format);
|
||||
if (format === "mach-o" || format === "mach-o-universal")
|
||||
return new MachOSliceArtifactReader(path, input.environment);
|
||||
throw new AnalysisUnsupportedTargetError(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { readFileHandlePrefix } from "../../filesystem/readFileHandlePrefix.js";
|
||||
import {
|
||||
sameRegularFileState,
|
||||
verifyRegularFileState,
|
||||
@@ -183,12 +184,14 @@ const classifyRootFormat = async (
|
||||
signal?: AbortSignal,
|
||||
): Promise<ArtifactOccurrence["artifact_format"]> => {
|
||||
abortIfNeeded(signal);
|
||||
const magic = Buffer.alloc(ARTIFACT_CLASSIFICATION_PREFIX_BYTES);
|
||||
const observed = await handle.read(magic, 0, magic.length, 0);
|
||||
const prefix = await readFileHandlePrefix(
|
||||
handle,
|
||||
ARTIFACT_CLASSIFICATION_PREFIX_BYTES,
|
||||
() => abortIfNeeded(signal),
|
||||
);
|
||||
abortIfNeeded(signal);
|
||||
await verifyRegularFileState(path, { handle, initial });
|
||||
abortIfNeeded(signal);
|
||||
const prefix = magic.subarray(0, observed.bytesRead);
|
||||
if (nesContainerFormat(prefix) !== undefined) {
|
||||
const parsed = parseInesLayout(prefix, initial.size);
|
||||
if (!parsed.ok) throw new ArtifactReaderFailure("format", parsed.error);
|
||||
|
||||
Reference in New Issue
Block a user