Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,35 @@ describe("bounded binary previews", () => {
}
});

it("opens extensionless UTF-8 text archive entries while rejecting binary ones", async () => {
const bytes = await new JSZip()
.file("CHANGELOG", "Release 1.2.3 notes")
.file("firmware", new Uint8Array([0x7f, 0x45, 0x4c, 0x46, 0x00, 0x01]))
.generateAsync({ type: "arraybuffer" });
const src = URL.createObjectURL(new Blob([bytes]));
try {
await using screen = await render(<BinaryViewer src={src} name="pkg.zip" kind="archive" />);
await vi.waitFor(
() => expect(screen.container.querySelectorAll("tbody button")).toHaveLength(2),
10_000,
);
await screen.getByRole("button", { name: "CHANGELOG" }).click();
await vi.waitFor(
() => expect(screen.container.textContent).toContain("Release 1.2.3 notes"),
10_000,
);
await screen.getByRole("button", { name: "Back to archive" }).click();
await screen.getByRole("button", { name: "firmware" }).click();
await vi.waitFor(() =>
expect(screen.container.querySelector('[role="alert"]')?.textContent).toContain(
"Only UTF-8 text and images can be opened inside an archive.",
),
);
} finally {
URL.revokeObjectURL(src);
}
});

it("keeps WhiteIsZero TIFF brightness and alpha with SubIFDs and type-13 ExifIFD pointers and rejects invalid metadata before decoding", async () => {
let bytes = new ArrayBuffer(0);
let exifEntry = 0;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/files/BinaryViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function ArchiveFile(props: { readonly path: string; readonly bytes: Uint8Array<
const [url, setUrl] = useState<string | null>(null);
const kind = filePreviewKind({ name: props.path });
const text = (() => {
if (!["text", "markdown", "html", "mermaid"].includes(kind)) return null;
if (!["text", "markdown", "html", "mermaid", "unsupported"].includes(kind)) return null;
try {
return decodeFilePreviewText(props.bytes);
} catch {
Expand Down
Loading