fix(electron): keep missing unpacked ASAR entries unavailable

This commit is contained in:
N0zoM1z0
2026-07-16 23:35:48 +09:00
committed by N0zoM1z0
parent aefdf512cd
commit fb6964a74e
5 changed files with 109 additions and 13 deletions
+21 -1
View File
@@ -375,6 +375,9 @@ const emptyScan = (): {
readonly pendingContradictions: PendingIntegrityContradiction[];
} => ({ nodes: new Map(), occurrences: [], pendingContradictions: [] });
const UNAVAILABLE_UNPACKED_LIMITATION =
"ASAR unpacked companion bytes were unavailable; no content hash or child artifact was produced.";
interface PendingIntegrityContradiction {
readonly logicalPath: string;
readonly declaredSha256: string;
@@ -497,7 +500,16 @@ const scanReader = async (
logicalPath,
parent?.occurrence_id ?? null,
);
const digested = await digestEntry(currentReader, entry, logicalPath);
let digested:
| { readonly node: ArtifactNode; readonly mismatched: boolean }
| undefined;
try {
digested = await digestEntry(currentReader, entry, logicalPath);
} catch (cause: unknown) {
if (!isUnavailableUnpackedEntry(cause, entry)) throw cause;
occurrence.hash_status = "unavailable";
occurrence.limitations.push(UNAVAILABLE_UNPACKED_LIMITATION);
}
if (digested !== undefined) {
nodes.set(digested.node.artifact_id, digested.node);
occurrence.artifact_id = digested.node.artifact_id;
@@ -519,6 +531,14 @@ const scanReader = async (
return { nodes, occurrences, pendingContradictions };
};
const isUnavailableUnpackedEntry = (
cause: unknown,
entry: ArtifactEntry,
): boolean =>
entry.unpacked &&
cause instanceof ArtifactReaderFailure &&
cause.reason === "unavailable";
const classifyRoot = async (
path: string,
directory: boolean,
+20
View File
@@ -82,6 +82,20 @@ export class AsarArtifactReader implements ArtifactReader {
Readable.from(extractFile(this.path, entry.adapterKey, false)),
);
} catch (cause: unknown) {
if (entry.unpacked && isMissingFile(cause))
return Promise.reject(
new ArtifactReaderFailure(
"unavailable",
`ASAR unpacked entry bytes are unavailable: ${entry.path}`,
{ cause },
{
logicalPath: entry.path,
declaredSha256: entry.declaredSha256,
calculatedSha256: null,
unpacked: true,
},
),
);
return Promise.reject(
asarFailure(this.path, `read ${entry.path}`, cause),
);
@@ -114,3 +128,9 @@ const asarFailure = (
`Malformed or unreadable ASAR during ${operation}: ${path}`,
{ cause },
);
const isMissingFile = (cause: unknown): boolean =>
typeof cause === "object" &&
cause !== null &&
"code" in cause &&
cause.code === "ENOENT";