Skip to content

The open-source app everyone uses to manage agents at work

fix(sandbox-providers): accept bsdtar listings in the syncOut tarball confinement check (#11289)

Devin Foleyc57c0f749810
diff --git a/packages/plugins/sandbox-providers/daytona/src/file-sync.ts b/packages/plugins/sandbox-providers/daytona/src/file-sync.ts
index 2e3a192caa..8a84dd5d34 100644
--- a/packages/plugins/sandbox-providers/daytona/src/file-sync.ts
+++ b/packages/plugins/sandbox-providers/daytona/src/file-sync.ts
@@ -179,6 +179,44 @@ function posixPathEscapes(relative: string): boolean {
return normalized === ".." || normalized.startsWith("../") || path.posix.isAbsolute(normalized);
}
+/**
+ * Parse one `tar -tvf` verbose listing line into its leading type flag and the
+ * trailing name-and-link-target field. The listing dialect depends on which tar
+ * the host ships: GNU/busybox emit
+ * `<perms> <owner>/<group> <size> <date> <time> <rest>`, while bsdtar
+ * (libarchive — the system tar on macOS) emits the ls-style
+ * `<perms> <links> <user> <group> <size> <Mon> <day> <time|year> <rest>`.
+ * The second field disambiguates: GNU always slash-joins owner/group, bsdtar
+ * puts a pure-digit link count there, so no line satisfies both shapes — the
+ * slash requirement is load-bearing, since a bsdtar line with numeric uid/gid
+ * would otherwise match the GNU shape shifted, hiding traversal in `<rest>`.
+ * Entries whose size column is not a plain byte count (e.g. a device node's
+ * `major,minor`) match neither shape. Returns null when nothing matches so
+ * callers can fail closed.
+ */
+export function parseTarVerboseListingLine(line: string): { typeFlag: string; rest: string } | null {
+ const gnu = line.match(/^(\S+)\s+\S+\/\S+\s+\d+\s+\S+\s+\S+\s+(.*)$/);
+ if (gnu) return { typeFlag: gnu[1][0], rest: gnu[2] };
+ const bsd = line.match(/^(\S+)\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d{1,2}\s+(?:\d{4}|\d{1,2}:\d{2}(?::\d{2})?)\s+(.*)$/);
+ if (bsd) return { typeFlag: bsd[1][0], rest: bsd[2] };
+ return null;
+}
+
+/**
+ * Split a verbose-listing link field (`<name><delimiter><target>`) exactly
+ * once. The sandbox controls both halves, so a field with zero or multiple
+ * delimiter occurrences is unresolvable: a link name that itself contains the
+ * delimiter shifts the split point, and taking the first (or last) occurrence
+ * would let a crafted name or target hide an escaping link target from the
+ * confinement check. Returns null so callers fail closed.
+ */
+export function splitLinkEntryOnce(field: string, delimiter: string): { name: string; target: string } | null {
+ const first = field.indexOf(delimiter);
+ if (first === -1) return null;
+ if (field.indexOf(delimiter, first + delimiter.length) !== -1) return null;
+ return { name: field.slice(0, first), target: field.slice(first + delimiter.length) };
+}
+
/**
* Reject a sandbox-authored tarball before extraction if any member would land
* outside the extraction dir. The archive is produced by the (untrusted) sandbox,
@@ -197,24 +235,23 @@ async function assertTarballEntriesConfined(archivePath: string): Promise<void>
});
const lines = stdout.split("\n").filter((line) => line.trim().length > 0);
for (const line of lines) {
- // GNU tar -tvf: "<perms> <owner>/<group> <size> <date> <time> <name>[ -> target]".
- const match = line.match(/^(\S+)\s+\S+\s+\d+\s+\S+\s+\S+\s+(.*)$/);
- if (!match) {
+ const parsed = parseTarVerboseListingLine(line);
+ if (!parsed) {
throw new Error(`Daytona syncOut refusing tarball with an unparseable entry listing: ${line}`);
}
- const typeFlag = match[1][0];
- let name = match[2];
+ const typeFlag = parsed.typeFlag;
+ let name = parsed.rest;
let linkTarget: string | null = null;
if (typeFlag === "l") {
- const idx = name.indexOf(" -> ");
- if (idx === -1) throw new Error(`Daytona syncOut refusing unparseable symlink entry: ${line}`);
- linkTarget = name.slice(idx + " -> ".length);
- name = name.slice(0, idx);
+ const split = splitLinkEntryOnce(name, " -> ");
+ if (!split) throw new Error(`Daytona syncOut refusing unparseable or ambiguous symlink entry: ${line}`);
+ name = split.name;
+ linkTarget = split.target;
} else if (typeFlag === "h") {
- const idx = name.indexOf(" link to ");
- if (idx === -1) throw new Error(`Daytona syncOut refusing unparseable hardlink entry: ${line}`);
- linkTarget = name.slice(idx + " link to ".length);
- name = name.slice(0, idx);
+ const split = splitLinkEntryOnce(name, " link to ");
+ if (!split) throw new Error(`Daytona syncOut refusing unparseable or ambiguous hardlink entry: ${line}`);
+ name = split.name;
+ linkTarget = split.target;
}
const cleanName = name.replace(/\/+$/, "");
if (cleanName.length > 0 && posixPathEscapes(cleanName)) {
diff --git a/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts b/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts
index 61d064961a..46d8567207 100644
--- a/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts
+++ b/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts
@@ -37,6 +37,7 @@ import plugin, {
} from "./plugin.js";
import type { PluginContext } from "@paperclipai/plugin-sdk";
import manifest from "./manifest.js";
+import { parseTarVerboseListingLine, splitLinkEntryOnce } from "./file-sync.js";
function createMockSandbox(overrides: {
id?: string;
@@ -3861,13 +3862,14 @@ describe("daytona native file-sync hooks", () => {
tempDirs.push(staging);
await fs.mkdir(path.join(staging, "sub"), { recursive: true });
await fs.writeFile(path.join(staging, "sub", "escape.txt"), "escape");
+ // GNU spells member-name rewriting --transform; bsdtar (macOS) spells it -s.
+ const gnuTar = execFileSync("tar", ["--version"]).toString().includes("GNU tar");
execFileSync("tar", [
"-cf",
req.destination!,
"-C",
path.join(staging, "sub"),
- "--transform",
- "s,^,../,",
+ ...(gnuTar ? ["--transform", "s,^,../,"] : ["-s", ",^,../,"]),
"escape.txt",
]);
return { source: req.source, result: req.destination };
@@ -3897,6 +3899,87 @@ describe("daytona native file-sync hooks", () => {
await expect(fs.stat(path.join(hostRoot, "escape.txt"))).rejects.toThrow();
});
+ it("syncOut refuses a sandbox-authored tarball carrying a symlink whose target escapes the extraction dir", async () => {
+ const hostRoot = await makeHostDir();
+ const restored = path.join(hostRoot, "restored");
+ const sandbox = createMockSandbox();
+ sandbox.fs.downloadFiles.mockImplementation(async (requests: Array<{ source: string; destination?: string }>) => {
+ return Promise.all(
+ requests.map(async (req) => {
+ // Craft a tar whose sole member is a symlink pointing above the tree.
+ const staging = await fs.mkdtemp(path.join(os.tmpdir(), "daytona-evil-"));
+ tempDirs.push(staging);
+ await fs.mkdir(path.join(staging, "sub"), { recursive: true });
+ await fs.symlink("../../outside.txt", path.join(staging, "sub", "evil"));
+ execFileSync("tar", ["-cf", req.destination!, "-C", path.join(staging, "sub"), "evil"]);
+ return { source: req.source, result: req.destination };
+ }),
+ );
+ });
+ mockGet.mockResolvedValue(sandbox);
+
+ await expect(
+ plugin.definition.onEnvironmentSyncOut?.({
+ driverKey: "daytona",
+ companyId: "company-1",
+ environmentId: "env-1",
+ config: { timeoutMs: 300000, reuseLease: false },
+ lease: syncLease(),
+ operations: [
+ {
+ operationId: "sync-op-out-symlink-escape",
+ files: [{ sourcePath: `${REMOTE_DIR}/proj`, targetPath: restored, kind: "directory" }],
+ },
+ ],
+ }),
+ ).rejects.toThrow(/link whose target escapes the extraction dir/);
+
+ // Fail-closed: the confinement check runs before extraction touches disk.
+ await expect(fs.stat(restored)).rejects.toThrow();
+ });
+
+ it("syncOut refuses a symlink whose name embeds the listing delimiter (ambiguous split hides the real target)", async () => {
+ const hostRoot = await makeHostDir();
+ const restored = path.join(hostRoot, "restored");
+ const sandbox = createMockSandbox();
+ sandbox.fs.downloadFiles.mockImplementation(async (requests: Array<{ source: string; destination?: string }>) => {
+ return Promise.all(
+ requests.map(async (req) => {
+ // A symlink literally named "evil -> decoy" with an escaping target
+ // lists as "evil -> decoy -> ../../outside.txt"; splitting at the
+ // first delimiter would validate "decoy -> ../../outside.txt" (which
+ // normalizes in-tree) while tar extracts the real escaping link.
+ const staging = await fs.mkdtemp(path.join(os.tmpdir(), "daytona-evil-"));
+ tempDirs.push(staging);
+ await fs.mkdir(path.join(staging, "sub"), { recursive: true });
+ await fs.symlink("../../outside.txt", path.join(staging, "sub", "evil -> decoy"));
+ execFileSync("tar", ["-cf", req.destination!, "-C", path.join(staging, "sub"), "evil -> decoy"]);
+ return { source: req.source, result: req.destination };
+ }),
+ );
+ });
+ mockGet.mockResolvedValue(sandbox);
+
+ await expect(
+ plugin.definition.onEnvironmentSyncOut?.({
+ driverKey: "daytona",
+ companyId: "company-1",
+ environmentId: "env-1",
+ config: { timeoutMs: 300000, reuseLease: false },
+ lease: syncLease(),
+ operations: [
+ {
+ operationId: "sync-op-out-ambiguous-symlink",
+ files: [{ sourcePath: `${REMOTE_DIR}/proj`, targetPath: restored, kind: "directory" }],
+ },
+ ],
+ }),
+ ).rejects.toThrow(/ambiguous symlink entry/);
+
+ // Fail-closed: the confinement check runs before extraction touches disk.
+ await expect(fs.stat(restored)).rejects.toThrow();
+ });
+
it("round-trips a directory (syncIn then syncOut) preserving contents, a 0600 file, and a preserved symlink", async () => {
const hostRoot = await makeHostDir();
const source = path.join(hostRoot, "src");
@@ -4383,3 +4466,86 @@ describe("daytona manifest form defaults", () => {
}
});
});
+
+describe("parseTarVerboseListingLine", () => {
+ it("parses GNU tar listing lines (file, dir, symlink, hardlink, numeric owner)", () => {
+ expect(parseTarVerboseListingLine("-rw-r--r-- daytona/daytona 7560 2026-08-11 21:43 AGENTS.md")).toEqual({
+ typeFlag: "-",
+ rest: "AGENTS.md",
+ });
+ expect(parseTarVerboseListingLine("drwxr-xr-x daytona/daytona 0 2026-08-11 21:43 nested/")).toEqual({
+ typeFlag: "d",
+ rest: "nested/",
+ });
+ expect(
+ parseTarVerboseListingLine("lrwxrwxrwx daytona/daytona 0 2026-08-11 21:43 shortcut -> nested/data.txt"),
+ ).toEqual({ typeFlag: "l", rest: "shortcut -> nested/data.txt" });
+ expect(
+ parseTarVerboseListingLine("hrw-r--r-- daytona/daytona 0 2026-08-11 21:43 copy.txt link to data.txt"),
+ ).toEqual({ typeFlag: "h", rest: "copy.txt link to data.txt" });
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0/0 12 2026-08-11 21:43 root-owned.txt")).toEqual({
+ typeFlag: "-",
+ rest: "root-owned.txt",
+ });
+ });
+
+ it("parses bsdtar (macOS) listing lines, including year-form dates", () => {
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0 daytona daytona 7560 Aug 11 21:43 AGENTS.md")).toEqual({
+ typeFlag: "-",
+ rest: "AGENTS.md",
+ });
+ expect(parseTarVerboseListingLine("drwxr-xr-x 0 daytona daytona 0 Aug 11 21:43 nested/")).toEqual({
+ typeFlag: "d",
+ rest: "nested/",
+ });
+ expect(
+ parseTarVerboseListingLine("lrwxr-xr-x 0 daytona daytona 0 Aug 11 21:43 shortcut -> nested/data.txt"),
+ ).toEqual({ typeFlag: "l", rest: "shortcut -> nested/data.txt" });
+ expect(
+ parseTarVerboseListingLine("hrw-r--r-- 0 daytona daytona 0 Aug 11 21:43 copy.txt link to data.txt"),
+ ).toEqual({ typeFlag: "h", rest: "copy.txt link to data.txt" });
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0 daytona daytona 7560 Aug 11 2025 old.txt")).toEqual({
+ typeFlag: "-",
+ rest: "old.txt",
+ });
+ });
+
+ it("keeps the true member name for bsdtar lines with numeric uid/gid, so traversal stays visible", () => {
+ // With unresolvable ids bsdtar prints bare numbers; a looser GNU-first parse
+ // would read this shape shifted by one field and report the member name as
+ // "21:43 ../escape.txt", hiding the leading "../" from the traversal check.
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0 1001 1001 7560 Aug 11 21:43 ../escape.txt")).toEqual({
+ typeFlag: "-",
+ rest: "../escape.txt",
+ });
+ });
+
+ it("returns null (fail closed) for lines matching neither dialect", () => {
+ expect(parseTarVerboseListingLine("not a tar listing line")).toBeNull();
+ expect(parseTarVerboseListingLine("tar: Error is not recoverable: exiting now")).toBeNull();
+ // Device nodes carry "major,minor" instead of a byte count in both dialects.
+ expect(parseTarVerboseListingLine("crw-rw-rw- root/root 1,3 2026-08-11 21:43 dev/null")).toBeNull();
+ expect(parseTarVerboseListingLine("crw-rw-rw- 0 root wheel 1,3 Aug 11 21:43 dev/null")).toBeNull();
+ });
+});
+
+describe("splitLinkEntryOnce", () => {
+ it("splits a clean single-delimiter link field", () => {
+ expect(splitLinkEntryOnce("shortcut -> nested/data.txt", " -> ")).toEqual({
+ name: "shortcut",
+ target: "nested/data.txt",
+ });
+ expect(splitLinkEntryOnce("copy.txt link to data.txt", " link to ")).toEqual({
+ name: "copy.txt",
+ target: "data.txt",
+ });
+ });
+
+ it("returns null (fail closed) when the delimiter is absent or appears more than once", () => {
+ expect(splitLinkEntryOnce("no delimiter here", " -> ")).toBeNull();
+ // A link name or target embedding the delimiter makes the split point
+ // unresolvable; either split choice can hide an escaping target.
+ expect(splitLinkEntryOnce("evil -> decoy -> ../../outside.txt", " -> ")).toBeNull();
+ expect(splitLinkEntryOnce("a link to b link to ../../outside.txt", " link to ")).toBeNull();
+ });
+});
diff --git a/packages/plugins/sandbox-providers/kubernetes/src/file-sync.ts b/packages/plugins/sandbox-providers/kubernetes/src/file-sync.ts
index f482efd769..6210999016 100644
--- a/packages/plugins/sandbox-providers/kubernetes/src/file-sync.ts
+++ b/packages/plugins/sandbox-providers/kubernetes/src/file-sync.ts
@@ -323,6 +323,44 @@ async function createHostTarball(input: {
);
}
+/**
+ * Parse one `tar -tvf` verbose listing line into its leading type flag and the
+ * trailing name-and-link-target field. The listing dialect depends on which tar
+ * the host ships: GNU/busybox emit
+ * `<perms> <owner>/<group> <size> <date> <time> <rest>`, while bsdtar
+ * (libarchive — the system tar on macOS) emits the ls-style
+ * `<perms> <links> <user> <group> <size> <Mon> <day> <time|year> <rest>`.
+ * The second field disambiguates: GNU always slash-joins owner/group, bsdtar
+ * puts a pure-digit link count there, so no line satisfies both shapes — the
+ * slash requirement is load-bearing, since a bsdtar line with numeric uid/gid
+ * would otherwise match the GNU shape shifted, hiding traversal in `<rest>`.
+ * Entries whose size column is not a plain byte count (e.g. a device node's
+ * `major,minor`) match neither shape. Returns null when nothing matches so
+ * callers can fail closed.
+ */
+export function parseTarVerboseListingLine(line: string): { typeFlag: string; rest: string } | null {
+ const gnu = line.match(/^(\S+)\s+\S+\/\S+\s+\d+\s+\S+\s+\S+\s+(.*)$/);
+ if (gnu) return { typeFlag: gnu[1][0], rest: gnu[2] };
+ const bsd = line.match(/^(\S+)\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d{1,2}\s+(?:\d{4}|\d{1,2}:\d{2}(?::\d{2})?)\s+(.*)$/);
+ if (bsd) return { typeFlag: bsd[1][0], rest: bsd[2] };
+ return null;
+}
+
+/**
+ * Split a verbose-listing link field (`<name><delimiter><target>`) exactly
+ * once. The sandbox controls both halves, so a field with zero or multiple
+ * delimiter occurrences is unresolvable: a link name that itself contains the
+ * delimiter shifts the split point, and taking the first (or last) occurrence
+ * would let a crafted name or target hide an escaping link target from the
+ * confinement check. Returns null so callers fail closed.
+ */
+export function splitLinkEntryOnce(field: string, delimiter: string): { name: string; target: string } | null {
+ const first = field.indexOf(delimiter);
+ if (first === -1) return null;
+ if (field.indexOf(delimiter, first + delimiter.length) !== -1) return null;
+ return { name: field.slice(0, first), target: field.slice(first + delimiter.length) };
+}
+
/**
* Reject a sandbox-authored tarball before extraction if any member would land
* outside the extraction dir. The archive is produced by the (untrusted) sandbox,
@@ -338,24 +376,23 @@ async function assertTarballEntriesConfined(archivePath: string): Promise<void>
});
const lines = stdout.split("\n").filter((line) => line.trim().length > 0);
for (const line of lines) {
- // GNU tar -tvf: "<perms> <owner>/<group> <size> <date> <time> <name>[ -> target]".
- const match = line.match(/^(\S+)\s+\S+\s+\d+\s+\S+\s+\S+\s+(.*)$/);
- if (!match) {
+ const parsed = parseTarVerboseListingLine(line);
+ if (!parsed) {
throw new Error(`Kubernetes syncOut refusing tarball with an unparseable entry listing: ${line}`);
}
- const typeFlag = match[1][0];
- let name = match[2];
+ const typeFlag = parsed.typeFlag;
+ let name = parsed.rest;
let linkTarget: string | null = null;
if (typeFlag === "l") {
- const idx = name.indexOf(" -> ");
- if (idx === -1) throw new Error(`Kubernetes syncOut refusing unparseable symlink entry: ${line}`);
- linkTarget = name.slice(idx + " -> ".length);
- name = name.slice(0, idx);
+ const split = splitLinkEntryOnce(name, " -> ");
+ if (!split) throw new Error(`Kubernetes syncOut refusing unparseable or ambiguous symlink entry: ${line}`);
+ name = split.name;
+ linkTarget = split.target;
} else if (typeFlag === "h") {
- const idx = name.indexOf(" link to ");
- if (idx === -1) throw new Error(`Kubernetes syncOut refusing unparseable hardlink entry: ${line}`);
- linkTarget = name.slice(idx + " link to ".length);
- name = name.slice(0, idx);
+ const split = splitLinkEntryOnce(name, " link to ");
+ if (!split) throw new Error(`Kubernetes syncOut refusing unparseable or ambiguous hardlink entry: ${line}`);
+ name = split.name;
+ linkTarget = split.target;
}
const cleanName = name.replace(/\/+$/, "");
if (cleanName.length > 0 && posixPathEscapes(cleanName)) {
diff --git a/packages/plugins/sandbox-providers/kubernetes/test/unit/file-sync.test.ts b/packages/plugins/sandbox-providers/kubernetes/test/unit/file-sync.test.ts
index b4b1fafde9..79104a9f6f 100644
--- a/packages/plugins/sandbox-providers/kubernetes/test/unit/file-sync.test.ts
+++ b/packages/plugins/sandbox-providers/kubernetes/test/unit/file-sync.test.ts
@@ -5,8 +5,10 @@ import path from "node:path";
import { spawn } from "node:child_process";
import {
assertConfinedSandboxPath,
+ parseTarVerboseListingLine,
performSyncIn,
performSyncOut,
+ splitLinkEntryOnce,
type PodStreamExec,
} from "../../src/file-sync.js";
@@ -756,3 +758,87 @@ describe("kubernetes onEnvironmentSyncIn (post-upload commands)", () => {
expect(emptyCalls).toHaveLength(1);
});
});
+
+
+describe("parseTarVerboseListingLine", () => {
+ it("parses GNU tar listing lines (file, dir, symlink, hardlink, numeric owner)", () => {
+ expect(parseTarVerboseListingLine("-rw-r--r-- daytona/daytona 7560 2026-08-11 21:43 AGENTS.md")).toEqual({
+ typeFlag: "-",
+ rest: "AGENTS.md",
+ });
+ expect(parseTarVerboseListingLine("drwxr-xr-x daytona/daytona 0 2026-08-11 21:43 nested/")).toEqual({
+ typeFlag: "d",
+ rest: "nested/",
+ });
+ expect(
+ parseTarVerboseListingLine("lrwxrwxrwx daytona/daytona 0 2026-08-11 21:43 shortcut -> nested/data.txt"),
+ ).toEqual({ typeFlag: "l", rest: "shortcut -> nested/data.txt" });
+ expect(
+ parseTarVerboseListingLine("hrw-r--r-- daytona/daytona 0 2026-08-11 21:43 copy.txt link to data.txt"),
+ ).toEqual({ typeFlag: "h", rest: "copy.txt link to data.txt" });
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0/0 12 2026-08-11 21:43 root-owned.txt")).toEqual({
+ typeFlag: "-",
+ rest: "root-owned.txt",
+ });
+ });
+
+ it("parses bsdtar (macOS) listing lines, including year-form dates", () => {
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0 daytona daytona 7560 Aug 11 21:43 AGENTS.md")).toEqual({
+ typeFlag: "-",
+ rest: "AGENTS.md",
+ });
+ expect(parseTarVerboseListingLine("drwxr-xr-x 0 daytona daytona 0 Aug 11 21:43 nested/")).toEqual({
+ typeFlag: "d",
+ rest: "nested/",
+ });
+ expect(
+ parseTarVerboseListingLine("lrwxr-xr-x 0 daytona daytona 0 Aug 11 21:43 shortcut -> nested/data.txt"),
+ ).toEqual({ typeFlag: "l", rest: "shortcut -> nested/data.txt" });
+ expect(
+ parseTarVerboseListingLine("hrw-r--r-- 0 daytona daytona 0 Aug 11 21:43 copy.txt link to data.txt"),
+ ).toEqual({ typeFlag: "h", rest: "copy.txt link to data.txt" });
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0 daytona daytona 7560 Aug 11 2025 old.txt")).toEqual({
+ typeFlag: "-",
+ rest: "old.txt",
+ });
+ });
+
+ it("keeps the true member name for bsdtar lines with numeric uid/gid, so traversal stays visible", () => {
+ // With unresolvable ids bsdtar prints bare numbers; a looser GNU-first parse
+ // would read this shape shifted by one field and report the member name as
+ // "21:43 ../escape.txt", hiding the leading "../" from the traversal check.
+ expect(parseTarVerboseListingLine("-rw-r--r-- 0 1001 1001 7560 Aug 11 21:43 ../escape.txt")).toEqual({
+ typeFlag: "-",
+ rest: "../escape.txt",
+ });
+ });
+
+ it("returns null (fail closed) for lines matching neither dialect", () => {
+ expect(parseTarVerboseListingLine("not a tar listing line")).toBeNull();
+ expect(parseTarVerboseListingLine("tar: Error is not recoverable: exiting now")).toBeNull();
+ // Device nodes carry "major,minor" instead of a byte count in both dialects.
+ expect(parseTarVerboseListingLine("crw-rw-rw- root/root 1,3 2026-08-11 21:43 dev/null")).toBeNull();
+ expect(parseTarVerboseListingLine("crw-rw-rw- 0 root wheel 1,3 Aug 11 21:43 dev/null")).toBeNull();
+ });
+});
+
+describe("splitLinkEntryOnce", () => {
+ it("splits a clean single-delimiter link field", () => {
+ expect(splitLinkEntryOnce("shortcut -> nested/data.txt", " -> ")).toEqual({
+ name: "shortcut",
+ target: "nested/data.txt",
+ });
+ expect(splitLinkEntryOnce("copy.txt link to data.txt", " link to ")).toEqual({
+ name: "copy.txt",
+ target: "data.txt",
+ });
+ });
+
+ it("returns null (fail closed) when the delimiter is absent or appears more than once", () => {
+ expect(splitLinkEntryOnce("no delimiter here", " -> ")).toBeNull();
+ // A link name or target embedding the delimiter makes the split point
+ // unresolvable; either split choice can hide an escaping target.
+ expect(splitLinkEntryOnce("evil -> decoy -> ../../outside.txt", " -> ")).toBeNull();
+ expect(splitLinkEntryOnce("a link to b link to ../../outside.txt", " link to ")).toBeNull();
+ });
+});