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

ZIP is valid on Linux, but not on Windows #66

Open
zadam opened this issue Dec 24, 2020 · 1 comment
Open

ZIP is valid on Linux, but not on Windows #66

zadam opened this issue Dec 24, 2020 · 1 comment

Comments

@zadam
Copy link

zadam commented Dec 24, 2020

Hi, I've encountered a strange issue with YAZL generated ZIPs. This is described in detail in zadam/trilium#1122 but here are the most relevant parts:

Example ZIP generated by YAZL: root.zip

On Linux it all seems fine:

$ unzip -t root.zip 
Archive:  root.zip
    testing: !!!meta.json             OK
    testing: root/                    OK
    testing: root/Trilium Demo.html   OK
    testing: root/Trilium Demo/       OK
    testing: root/Trilium Demo/Formatting examples/   OK
    testing: root/Trilium Demo/Formatting examples/School schedule.html   OK
...
    testing: root/Trilium Demo/Statistics/Note type count/template/js/renderTable.js   OK
    testing: root/Trilium Demo/Statistics/Note type count/template/js/renderPieChart.clone.html   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/template.html   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/template/   OK
    testing: root/Trilium Demo/Statistics/Most cloned notes/template/js.js   OK
    testing: navigation.html          OK
    testing: index.html               OK
    testing: style.css                OK
No errors detected in compressed data of root.zip.

But on windows most apps seem to report checksum errors:

image

image

Any idea what might be causing this?

@chdh
Copy link

chdh commented Aug 11, 2021

This error occurs when you pass a string to addBuffer() instead of a buffer. Trilium Notes has done that, before it switched from Yazl to Archiver. When the content string contains non-ASCII characters, the number of characters will differ from the number of bytes.

Test case:

const yazl = require("yazl");
const fs = require("fs");

const zipfile = new yazl.ZipFile();
zipfile.addBuffer("A \u00E4 Z", "test.txt");
zipfile.outputStream.pipe(fs.createWriteStream("test.zip"));
zipfile.end();

In this example, the number of characters is 5, but the number of UTF-8 encoded bytes in 6. In the ZIP directory entry the file size is 5, which is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants