GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): skip unresolvable TAR hard links instead of failing the arc… · pingdotgg/t3code@2075331

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/files
    • AttachmentFilePreview.browser.test.tsx
    • binaryPreview.worker.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx
+29-34Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -193,42 +193,37 @@ describe("bounded binary previews", () => {
193193
if (linked.type !== "entry") throw new Error("Expected hard link entry");
194194
expect(new TextDecoder().decode(linked.bytes)).toBe("hello world");
195195
}
196-
for (const chunks of [
197-
[block("alias.txt", encode(""), "1", 0, "missing.txt")],
198-
[block("self.txt", encode(""), "1", 0, "self.txt")],
199-
[block("alias.txt", encode(""), "1", 0, "later.txt"), block("later.txt", encode("hello"))],
200-
[block("a.txt", encode(""), "1", 0, "b.txt"), block("b.txt", encode(""), "1", 0, "a.txt")],
201-
[block("folder/", encode(""), "5"), block("alias.txt", encode(""), "1", 0, "folder/")],
202-
[
203-
block("original.txt", encode("hello")),
204-
block("Local", attributes({ linkpath: "" }), "x"),
205-
block("alias.txt", encode(""), "1", 0, "original.txt"),
206-
],
207-
[
208-
block("original.txt", encode("hello")),
209-
block("LongLink", encode("original.txt\0"), "K"),
210-
block("Global", attributes({ linkpath: "" }), "g"),
211-
block("alias.txt", encode(""), "1", 0, "original.txt"),
212-
],
213-
[
196+
const unresolved = new Uint8Array(
197+
await new Blob([
198+
block("missing.txt", encode(""), "1", 0, "nowhere.txt"),
199+
block("early.txt", encode(""), "1", 0, "later.txt"),
200+
block("later.txt", encode("hello")),
201+
block("folder/", encode(""), "5"),
202+
block("to-folder.txt", encode(""), "1", 0, "folder/"),
214203
block("replaced.txt", encode("stale")),
215204
block("replaced.txt", encode(""), "2", 0, "elsewhere.txt"),
216-
block("alias.txt", encode(""), "1", 0, "replaced.txt"),
217-
],
218-
[
219-
block("folder", encode("stale")),
220-
block("folder/", encode(""), "5"),
221-
block("alias.txt", encode(""), "1", 0, "folder"),
222-
],
223-
]) {
224-
const archive = new Uint8Array(await new Blob(chunks).arrayBuffer());
225-
expect(
226-
await request({ type: "open", kind: "archive", name: "link.tar", bytes: archive.buffer }),
227-
).toEqual({
228-
type: "error",
229-
message: "A TAR hard link does not refer to an earlier file in this archive.",
230-
});
231-
}
205+
block("to-replaced.txt", encode(""), "1", 0, "replaced.txt"),
206+
block("Local", attributes({ linkpath: "" }), "x"),
207+
block("emptied.txt", encode(""), "1", 0, "later.txt"),
208+
new Uint8Array(1024),
209+
]).arrayBuffer(),
210+
);
211+
const skipped = await request({
212+
type: "open",
213+
kind: "archive",
214+
name: "links.tar",
215+
bytes: unresolved.buffer,
216+
});
217+
if (skipped.type !== "archive") throw new Error("Expected archive");
218+
expect(skipped.entries.map((entry) => entry.path)).toEqual([
219+
"later.txt",
220+
"folder/",
221+
"replaced.txt",
222+
]);
223+
expect(await request({ type: "entry", path: "replaced.txt" })).toEqual({
224+
type: "error",
225+
message: "This archive entry is unavailable.",
226+
});
232227
} finally {
233228
worker.terminate();
234229
}
Collapse file

‎apps/web/src/components/files/binaryPreview.worker.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/binaryPreview.worker.ts
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,19 @@ function tarEntries(bytes: Uint8Array<ArrayBuffer>) {
122122
}
123123
cursor = end;
124124
}
125-
} else if (type === "" || type === "0" || type === "1" || type === "5") {
125+
} else if (
126+
type === "" ||
127+
type === "0" ||
128+
type === "5" ||
129+
// A hard link shares an earlier member's bytes; one without that member is skipped.
130+
(type === "1" && linkpath && files.has(linkpath))
131+
) {
126132
if (attributes.mtime && !/^[+-]?\d+(?:\.\d+)?$/.test(attributes.mtime))
127133
throw new Error("The TAR metadata is damaged.");
128134
const modified =
129135
(attributes.mtime ? Number(attributes.mtime) : number(offset + 136, 12)) * 1000;
130136
const date = new Date(modified);
131-
// TAR hard links name an earlier member; sharing its bytes also resolves chains in one pass.
132-
const linked = type === "1" && linkpath ? files.get(linkpath) : undefined;
133-
if (type === "1" && !linked)
134-
throw new Error("A TAR hard link does not refer to an earlier file in this archive.");
137+
const linked = type === "1" ? files.get(linkpath) : undefined;
135138
entries.push({
136139
path,
137140
size: linked?.length ?? size,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.