Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

fix(fileEditor): only offer archive extraction for .zip files (#8722)

brios7d6aa341aa53
diff --git a/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsx b/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsx
index 8acf927e17..98105c2d99 100644
--- a/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsx
+++ b/frontend/src/editor/core/components/fileEditor/FileEditorThumbnail.tsx
@@ -144,14 +144,6 @@ const FileEditorThumbnail = ({
return (m?.[1] || "").toUpperCase();
}, [file.name]);
- const extLower = useMemo(() => {
- const m = /\.([a-z0-9]+)$/i.exec(file.name ?? "");
- return (m?.[1] || "").toLowerCase();
- }, [file.name]);
-
- const isCBZ = extLower === "cbz";
- const isCBR = extLower === "cbr";
-
// Guests have no server storage to save or share into.
const uploadEnabled = config?.storageEnabled === true && !isAnonymous;
const sharingEnabled =
@@ -467,7 +459,7 @@ const FileEditorThumbnail = ({
});
}
},
- hidden: !isZipFile || !onUnzipFile || isCBZ || isCBR,
+ hidden: !isZipFile || !onUnzipFile,
},
{
id: "versionHistory",
@@ -496,8 +488,6 @@ const FileEditorThumbnail = ({
file.name,
file.versionNumber,
isZipFile,
- isCBZ,
- isCBR,
isPinned,
isDamaged,
damagedRepair,
diff --git a/frontend/src/editor/core/components/shared/signing/CreateSessionFlow.test.tsx b/frontend/src/editor/core/components/shared/signing/CreateSessionFlow.test.tsx
index f0b01751c6..ee086c236d 100644
--- a/frontend/src/editor/core/components/shared/signing/CreateSessionFlow.test.tsx
+++ b/frontend/src/editor/core/components/shared/signing/CreateSessionFlow.test.tsx
@@ -4,7 +4,7 @@ import userEvent from "@testing-library/user-event";
import { MantineProvider } from "@mantine/core";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MemoryRouter } from "react-router-dom";
-import { beforeEach, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { CreateSessionFlow } from "@editor/components/shared/signing/CreateSessionFlow";
import UserSelector from "@editor/components/shared/UserSelector";
import { qk } from "@editor/query/keys";
@@ -15,6 +15,13 @@ vi.mock("@editor/hooks/useIsMobile", () => ({
}));
beforeEach(() => {
viewport.mobile = false;
+ // The date picker opens on the current month. Pin it so the fixed
+ // October 2026 dates below stay on screen as the real clock advances.
+ vi.useFakeTimers({ toFake: ["Date"] });
+ vi.setSystemTime(new Date(2026, 9, 15, 12, 0, 0));
+});
+afterEach(() => {
+ vi.useRealTimers();
});
vi.mock("react-i18next", () => ({
diff --git a/frontend/src/editor/core/services/zipFileService.test.ts b/frontend/src/editor/core/services/zipFileService.test.ts
index 1a532cb7da..ba5742837a 100644
--- a/frontend/src/editor/core/services/zipFileService.test.ts
+++ b/frontend/src/editor/core/services/zipFileService.test.ts
@@ -20,6 +20,63 @@ function fakeBlob(bytes: number[], type = ""): Blob {
const PDF_BYTES = [0x25, 0x50, 0x44, 0x46, 0x2d, 0x31, 0x2e, 0x37]; // "%PDF-1.7"
+describe("zipFileService.isZipFile", () => {
+ test("accepts .zip whatever MIME the browser reports", () => {
+ for (const type of ["application/zip", "application/octet-stream", ""]) {
+ expect(
+ zipFileService.isZipFile(new File(["PK"], "archive.zip", { type })),
+ ).toBe(true);
+ }
+ });
+
+ test("accepts the extension case-insensitively", () => {
+ expect(zipFileService.isZipFile(new File(["PK"], "ARCHIVE.ZIP"))).toBe(
+ true,
+ );
+ });
+
+ test("rejects ZIP-based documents and comics", () => {
+ for (const name of [
+ "report.docx",
+ "sheet.xlsx",
+ "slides.pptx",
+ "notes.odt",
+ "book.epub",
+ "comic.cbz",
+ "comic.cbr",
+ ]) {
+ for (const type of ["application/zip", "application/octet-stream"]) {
+ expect(zipFileService.isZipFile(new File(["PK"], name, { type }))).toBe(
+ false,
+ );
+ }
+ }
+ });
+
+ test("rejects an untyped archive without a .zip name", () => {
+ expect(
+ zipFileService.isZipFile(
+ new File(["PK"], "download", { type: "application/zip" }),
+ ),
+ ).toBe(false);
+ });
+});
+
+describe("zipFileService.isZipFileStub", () => {
+ const stub = (name: string, type = "") =>
+ ({ name, type }) as Parameters<typeof zipFileService.isZipFileStub>[0];
+
+ test("follows the same archive-name rule as the File variant", () => {
+ expect(zipFileService.isZipFileStub(stub("archive.zip"))).toBe(true);
+ expect(
+ zipFileService.isZipFileStub(stub("report.docx", "application/zip")),
+ ).toBe(false);
+ expect(
+ zipFileService.isZipFileStub(stub("comic.cbz", "application/zip")),
+ ).toBe(false);
+ });
+});
+
describe("zipFileService.isZipResponse", () => {
describe("signature is authoritative", () => {
test("PK\\x03\\x04 -> ZIP", async () => {
diff --git a/frontend/src/editor/core/services/zipFileService.ts b/frontend/src/editor/core/services/zipFileService.ts
index 8c59408769..50b1d299a5 100644
--- a/frontend/src/editor/core/services/zipFileService.ts
+++ b/frontend/src/editor/core/services/zipFileService.ts
@@ -66,14 +66,23 @@ export class ZipFileService {
public static readonly ZIP_WARNING_THRESHOLD = 20;
// ZIP file validation constants
- private static readonly VALID_ZIP_TYPES = [
- "application/zip",
- "application/x-zip-compressed",
- "application/x-zip",
- "application/octet-stream", // Some browsers use this for ZIP files
- ];
private static readonly VALID_ZIP_EXTENSIONS = [".zip"];
+ /**
+ * ZIP is a container format, not a promise that the file is an archive.
+ * DOCX, ODT, EPUB and CBZ are ZIPs internally too, and extracting their
+ * parts would hand the user XML fragments instead of a document. Only a
+ * `.zip` name is something the archive extractor should open.
+ */
+ private static isZipArchiveName(name: string | undefined): boolean {
+ return (
+ typeof name === "string" &&
+ ZipFileService.VALID_ZIP_EXTENSIONS.some((ext) =>
+ name.toLowerCase().endsWith(ext),
+ )
+ );
+ }
+
/**
* Validate a ZIP file without extracting it
*/
@@ -300,28 +309,17 @@ export class ZipFileService {
}
/**
- * Check if a file is a ZIP file based on type and extension
+ * Check whether a file is an extractable `.zip` archive. MIME type alone is
+ * not enough: browsers report ZIP-based documents as `application/zip` or
+ * `application/octet-stream`, which would wrongly offer to extract them.
*/
public isZipFile(file: File): boolean {
- const hasValidType = ZipFileService.VALID_ZIP_TYPES.includes(file.type);
- const hasValidExtension = ZipFileService.VALID_ZIP_EXTENSIONS.some((ext) =>
- file.name.toLowerCase().endsWith(ext),
- );
-
- return hasValidType || hasValidExtension;
+ return ZipFileService.isZipArchiveName(file.name);
}
- /**
- * Check if a StirlingFileStub represents a ZIP file (for UI checks without loading full file)
- */
+ /** Stub variant of {@link isZipFile}, for UI checks without loading the bytes. */
public isZipFileStub(stub: StirlingFileStub): boolean {
- const hasValidType =
- stub.type && ZipFileService.VALID_ZIP_TYPES.includes(stub.type);
- const hasValidExtension = ZipFileService.VALID_ZIP_EXTENSIONS.some((ext) =>
- stub.name.toLowerCase().endsWith(ext),
- );
-
- return hasValidType || hasValidExtension;
+ return ZipFileService.isZipArchiveName(stub.name);
}
// Signature-first ZIP detection for HTTP response bodies. Content-Type alone
diff --git a/frontend/src/editor/core/tests/stubbed/archive-extract-eligibility.spec.ts b/frontend/src/editor/core/tests/stubbed/archive-extract-eligibility.spec.ts
new file mode 100644
index 0000000000..3509323212
--- /dev/null
+++ b/frontend/src/editor/core/tests/stubbed/archive-extract-eligibility.spec.ts
@@ -0,0 +1,121 @@
+import { test, expect } from "@editor/tests/helpers/stub-test-base";
+import { dismissTourTooltip } from "@editor/tests/helpers/ui-helpers";
+import type { Locator, Page } from "@playwright/test";
+import JSZip from "jszip";
+
+/**
+ * ZIP-based documents are containers, not archives: only `.zip` files may be
+ * auto-extracted or offered the Unzip action.
+ */
+
+test.use({ autoGoto: false, viewport: { width: 1600, height: 900 } });
+
+interface UploadPayload {
+ name: string;
+ mimeType: string;
+ buffer: Buffer;
+}
+
+async function zip(
+ entries: Record<string, string | Uint8Array>,
+): Promise<Buffer> {
+ const archive = new JSZip();
+ for (const [name, content] of Object.entries(entries)) {
+ archive.file(name, content);
+ }
+ return Buffer.from(await archive.generateAsync({ type: "uint8array" }));
+}
+
+async function uploadPayloads(page: Page, payloads: UploadPayload[]) {
+ await page.getByTestId("files-button").click();
+ await page.locator('[data-testid="file-input"]').setInputFiles(payloads);
+ for (const payload of payloads) {
+ await expect(
+ page.locator(".file-sidebar-file-item").filter({ hasText: payload.name }),
+ ).toHaveCount(1, { timeout: 20_000 });
+ }
+}
+
+async function switchToActiveFiles(page: Page) {
+ await page
+ .locator('[data-tour="view-switcher"]')
+ .first()
+ .locator(".mantine-SegmentedControl-label", { hasText: "Active Files" })
+ .click();
+}
+
+function card(page: Page, name: string): Locator {
+ return page
+ .locator('[data-testid="file-thumbnail"]')
+ .filter({ hasText: name });
+}
+
+const DOCX = await zip({
+ "[Content_Types].xml": "<Types/>",
+ "word/document.xml": "<document/>",
+});
+const ODT = await zip({
+ mimetype: "application/vnd.oasis.opendocument.text",
+ "content.xml": "<document/>",
+});
+const CBZ = await zip({ "page-01.png": "image" });
+const CBR = Buffer.from("Rar!\x1a\x07\x00", "binary");
+const REAL_ZIP = await zip({
+ "index.html": "<html></html>",
+ "assets/app.js": "console.log('hi')",
+});
+const REAL_ZIP_PAYLOAD: UploadPayload = {
+ name: "site.zip",
+ mimeType: "application/zip",
+ buffer: REAL_ZIP,
+};
+
+// The browser may report a document container as a generic binary or even as
+// application/zip; neither changes what the file actually is.
+const CONTAINERS: UploadPayload[] = [
+ { name: "report.docx", mimeType: "application/octet-stream", buffer: DOCX },
+ { name: "notes.odt", mimeType: "application/octet-stream", buffer: ODT },
+ { name: "comic.cbz", mimeType: "application/zip", buffer: CBZ },
+ { name: "comic.cbr", mimeType: "application/x-rar-compressed", buffer: CBR },
+];
+
+async function openActiveFiles(page: Page, payloads: UploadPayload[]) {
+ await page.goto("/editor", {
+ waitUntil: "domcontentloaded",
+ timeout: 120_000,
+ });
+ await uploadPayloads(page, payloads);
+ await dismissTourTooltip(page);
+ await switchToActiveFiles(page);
+}
+
+test.describe("Archive extraction eligibility", () => {
+ test("ZIP-based documents are kept intact and never offered Unzip", async ({
+ page,
+ }) => {
+ await openActiveFiles(page, CONTAINERS);
+
+ for (const payload of CONTAINERS) {
+ const fileCard = card(page, payload.name);
+ await expect(fileCard).toBeVisible({ timeout: 20_000 });
+ await fileCard.hover();
+ await expect(fileCard.getByRole("button", { name: "Unzip" })).toHaveCount(
+ 0,
+ );
+ }
+
+ // The DOCX/ODT internals were not extracted into the workbench.
+ await expect(page.getByText("[Content_Types].xml")).toHaveCount(0);
+ await expect(page.getByText("word/document.xml")).toHaveCount(0);
+ await expect(page.getByText("content.xml")).toHaveCount(0);
+ });
+
+ test("a real .zip archive still offers Unzip", async ({ page }) => {
+ await openActiveFiles(page, [REAL_ZIP_PAYLOAD]);
+
+ const fileCard = card(page, "site.zip");
+ await expect(fileCard).toBeVisible({ timeout: 20_000 });
+ await fileCard.hover();
+ await expect(fileCard.getByRole("button", { name: "Unzip" })).toBeVisible();
+ });
+});