diff --git a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx index 3cd65800545a3..2530d1d6a9a38 100644 --- a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx +++ b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx @@ -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(); + 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; diff --git a/apps/web/src/components/files/BinaryViewer.tsx b/apps/web/src/components/files/BinaryViewer.tsx index 262fdef5253c8..546d145e17193 100644 --- a/apps/web/src/components/files/BinaryViewer.tsx +++ b/apps/web/src/components/files/BinaryViewer.tsx @@ -59,7 +59,7 @@ function ArchiveFile(props: { readonly path: string; readonly bytes: Uint8Array< const [url, setUrl] = useState(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 {