Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(local-installation): fail a refused kit archive instead of hanging
Dongdong Chen3d9c30370897
diff --git a/packages/local-installation/src/localmodels-tool.test.ts b/packages/local-installation/src/localmodels-tool.test.tsindex be2c6b64..d4b94319 100644--- a/packages/local-installation/src/localmodels-tool.test.ts+++ b/packages/local-installation/src/localmodels-tool.test.ts@@ -10,6 +10,8 @@ import {rename,stat,utimes,+ symlink,+ link,} from "node:fs/promises";import { createHash } from "node:crypto";import path from "node:path";@@ -276,6 +278,46 @@ test.skipIf(process.platform === "win32")();},);+// A refused member must reject the install, not leave the extraction pending.+for (const [label, add] of [+ [+ "a symlink",+ (kit: string) => symlink("/etc/passwd", path.join(kit, "link")),+ ],+ [+ "a hard link",+ (kit: string) =>+ link(path.join(kit, "tool.json"), path.join(kit, "tool-copy.json")),+ ],+] as const)+ test.skipIf(process.platform === "win32")(+ `rejects a kit archive holding ${label} instead of hanging`,+ async () => {+ const f = await fixture();+ await chmod(f.directory, 0o700);+ await add(f.directory);+ const archive = path.join(f.home, "kit.tgz");+ execFileSync("tar", ["-czf", archive, "-C", f.directory, "."], {+ env: { ...process.env, COPYFILE_DISABLE: "1" },+ });+ await rm(f.directory, { recursive: true, force: true });+ const bytes = await readFile(archive);+ const source = { ...f.source, sha256: hash(bytes), bytes: bytes.length };+ await expect(+ ensureLocalmodelsTool(+ f.home,+ {},+ { source, fetcher: async () => new Response(bytes) },+ ),+ ).rejects.toThrow("Unsafe upstream tool archive.");+ expect(+ (await readdir(path.join(f.home, "tools/localmodels"))).filter((name) =>+ /^pending-|\.tgz$/.test(name),+ ),+ ).toEqual([]);+ },+ 5000,+ );test("does not silently fall back to a user Python or local implementation", async () => {const f = await fixture();vi.stubEnv("LINGER_LOCALMODELS_TOOL_JSON", "");diff --git a/packages/local-installation/src/localmodels-tool.ts b/packages/local-installation/src/localmodels-tool.tsindex de7981b1..66e1551b 100644--- a/packages/local-installation/src/localmodels-tool.ts+++ b/packages/local-installation/src/localmodels-tool.ts@@ -186,6 +186,15 @@ const location = (tool: Awaited<ReturnType<typeof verify>>) => ({});async function unpack(archive: string, directory: string) {let size = 0;+ // tar calls the filter from a stream event, so an error thrown there would+ // escape as an uncaught exception and leave extract() pending forever.+ // Record the first refusal, skip every later member, and throw afterwards,+ // as native-dependencies.ts does.+ let refused: Error | undefined;+ const refuse = (message: string) => {+ refused ??= new Error(message);+ return false;+ };await extract({file: archive,cwd: directory,@@ -200,18 +209,20 @@ async function unpack(archive: string, directory: string) {: entry.isFile()? "File": "Unsupported";+ if (refused) return false;const relative = name.replace(/^\.\//, "").replace(/\/$/, "");if (!relative) return type === "Directory";if (!safeRelative(relative) || !["File", "Directory"].includes(type))- throw new Error("Unsafe upstream tool archive.");+ return refuse("Unsafe upstream tool archive.");size += entry.size;if (size > 1024 ** 3)- throw new Error(+ return refuse("Upstream tool archive exceeds its extracted size limit.",);return true;},});+ if (refused) throw refused;}/*** Verified kits are sealed read-only: upstream children that run the kit's