Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non image files are currupted during zip import #6229

Closed
aponad opened this issue Nov 29, 2023 · 1 comment
Closed

Non image files are currupted during zip import #6229

aponad opened this issue Nov 29, 2023 · 1 comment
Assignees
Labels

Comments

@aponad
Copy link

aponad commented Nov 29, 2023

All non image files imported to Outline are currupted.

To Reproduce
Steps to reproduce the behavior:

  1. Create markdown document with non image file as attachment.
  2. Archive this directory.
  3. Import it to Outline.
  4. Download attachement.
  5. Try opening it.

Expected behavior
Imported files are not modified or corrupted.

Outline (please complete the following information):

  • Install: self hosted (Docker)
  • Version: v0.73.1

Works fine on v0.72.2 and I was unable to recreate it on main branch with node v18 or v20 (switch to yauzl seems to fix it).

I think this is related to node-unzipper library and this issue ZJONSSON/node-unzipper#286 (comment).


I am able to reproduce this problem in v0.73.1 ImportMarkdownZipTask.test.ts tests:

  it("should not corrupt files in zip", async () => {
    const fileOperation = await buildFileOperation();
    Object.defineProperty(fileOperation, "stream", {
      get() {
        return fs.createReadStream(
          path.resolve(__dirname, "..", "..", "test", "fixtures", "outline-markdown-with-pdf.zip")
        );
      },
    });
    jest.spyOn(FileOperation, "findByPk").mockResolvedValue(fileOperation);

    const props = {
      fileOperationId: fileOperation.id,
    };

    const task = new ImportMarkdownZipTask();
    const response = await task.perform(props);

    expect(response.attachments.size).toEqual(1);

    const attachments = Array.from(response.attachments.values());
    const attachment = attachments.find((att) =>
      att.key.endsWith("license.pdf")
    );

    attachment?.buffer.then((buffer) => {
      const md5 = createHash("md5");
      md5.write(buffer);
      const hash = md5.digest().toString("hex");
      expect(hash).toEqual("bda05f729bb1cfc11a08576d738b5add");
    });
  }, 10000);

Fixture: outline-markdown-with-pdf.zip

@aponad aponad added the bug label Nov 29, 2023
@tommoor
Copy link
Member

tommoor commented Nov 29, 2023

Hi @aponad thanks for filing – I was able to confirm with your test that this is already fixed on main (we removed unzipper due to similar issues elsewhere).

@tommoor tommoor closed this as completed Nov 29, 2023
@tommoor tommoor self-assigned this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants