fix(artifacts): take nested container families from bytes (#1553)
Inventory gave nested members a ZIP or ASAR family from their path suffix. Byte classification replaced it only for ZIP magic, so text named `.apk` or `.asar` stayed a container, and encrypted entries and symlinks kept the suffix guess. A filesystem `.asar` without an ASAR header failed the whole inventory as a malformed archive. Nested ZIP families now follow ZIP magic and ASAR follows its header pickle, shared with root classification. An unread member named like a container has an unknown format and a limitation naming the suffix. ASAR expansion requires the header. The Android projection adds a limitation when no root AndroidManifest.xml was observed, and its rejection names the observed root format. Fixes #1491 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c8fd2f152b
commit
4b985e5021
@@ -6,10 +6,7 @@ import {
|
||||
import type { FileHandle } from "node:fs/promises";
|
||||
import type { Stats } from "node:fs";
|
||||
|
||||
import {
|
||||
classifyArtifactBytes,
|
||||
classifyArtifactContent,
|
||||
} from "./ArtifactGraphConstruction.js";
|
||||
import { classifyArtifactContent } from "./ArtifactGraphConstruction.js";
|
||||
import { ARTIFACT_CLASSIFICATION_PREFIX_BYTES } from "../ArtifactHash.js";
|
||||
import type { ArtifactOccurrence } from "../../domain/artifactGraph.js";
|
||||
import {
|
||||
@@ -78,35 +75,15 @@ const classifyRootFormat = async (
|
||||
const prefix = magic.subarray(0, observed.bytesRead);
|
||||
const lower = path.toLowerCase();
|
||||
if (hasZipSignature(prefix)) return zipPackageFormatForPath(lower) ?? "zip";
|
||||
if (lower.endsWith(".asar") && hasAsarHeader(prefix)) return "asar";
|
||||
if (
|
||||
lower.endsWith(".pkg") &&
|
||||
prefix.subarray(0, 4).toString("ascii") === "xar!"
|
||||
)
|
||||
return "pkg";
|
||||
if (lower.endsWith(".dmg") && (await hasKolyTrailer(handle))) return "dmg";
|
||||
const size = (await handle.stat()).size;
|
||||
const format = classifyArtifactContent(path, prefix, size).format;
|
||||
// Path suffixes stay role hints for nested members. A root whose container
|
||||
// magic did not match is classified from the bytes that were read.
|
||||
if (format === "asar" || format === "pkg" || format === "dmg")
|
||||
return classifyArtifactBytes(prefix, size);
|
||||
return format;
|
||||
};
|
||||
|
||||
/**
|
||||
* Electron ASAR starts with a size pickle whose payload is one uint32, then
|
||||
* a header pickle whose payload begins with a JSON object.
|
||||
*/
|
||||
const hasAsarHeader = (prefix: Buffer): boolean => {
|
||||
if (prefix.length < 16 || prefix.readUInt32LE(0) !== 4) return false;
|
||||
const headerSize = prefix.readUInt32LE(4);
|
||||
const payloadSize = prefix.readUInt32LE(8);
|
||||
if (headerSize < 16 || payloadSize !== headerSize - 4) return false;
|
||||
const stringLength = prefix.readUInt32LE(12);
|
||||
return (
|
||||
stringLength >= 2 && stringLength <= payloadSize - 4 && prefix[16] === 0x7b
|
||||
);
|
||||
// ASAR is chosen from its header pickle; any other suffix is a role hint.
|
||||
return classifyArtifactContent(path, prefix, (await handle.stat()).size)
|
||||
.format;
|
||||
};
|
||||
|
||||
const hasKolyTrailer = async (handle: FileHandle): Promise<boolean> => {
|
||||
|
||||
Reference in New Issue
Block a user