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 does not support >65,535 files #229

Open
kajkal opened this issue Jan 27, 2025 · 0 comments · May be fixed by #230
Open

zip does not support >65,535 files #229

kajkal opened this issue Jan 27, 2025 · 0 comments · May be fixed by #230

Comments

@kajkal
Copy link

kajkal commented Jan 27, 2025

Zip class streams, zip and zipSync functions do not correctly support saving a .zip file with more than 65,535 file entries.

How to reproduce

node:

import * as fflate from 'fflate';

const entries = Array.from({ length: 70_000 }, (_, i) => [ `${i}`, fflate.strToU8(`Content ${i}`) ]);

{
    const zipped = fflate.zipSync(Object.fromEntries(entries));
    const files = Object.entries(fflate.unzipSync(zipped));
    console.log(`in zip created by zipSync function: ${files.length} files found`);
}
{
    fflate.zip(Object.fromEntries(entries), (err, zipped) => {
        if (err) throw err;
        const files = Object.entries(fflate.unzipSync(zipped));
        console.log(`in zip created by zip async function: ${files.length} files found`);
    });
}
{
    const chunks = [];
    const zip = new fflate.Zip((err, chunk, final) => {
        if (err) throw err;
        chunks.push(chunk);
        if (final) {
            const zipped = Buffer.concat(chunks);
            const files = Object.entries(fflate.unzipSync(zipped));
            console.log(`in zip created by Zip streams: ${files.length} files found`);
        }
    });
    for (const [ fileName, content ] of entries) {
        const file = new fflate.ZipPassThrough(fileName);
        zip.add(file);
        file.push(content, true);
    }
    zip.end();
}

/*
in zip created by zipSync function: 4464 files found
in zip created by zip async function: 4464 files found
in zip created by Zip streams: 4464 files found
*/

browser:

https://jsfiddle.net/uo568c9a/

The problem

Currently, when saving a .zip file containing more than 65,535 files, a corrupted archive is created - some 3rd party software cannot properly find all files, fflate itself is no exception!
This is caused by overflow of the 16 bits intended for information of the number of files in the standard EOCD record.
fflate v0.8.2 is able to read Zip64 EOCD record/locator, but is unable of writing such data.

related #137 (unzip does not support >65,535 files)

@101arrowz thank you for your time and this library, much appreciated!

@kajkal kajkal linked a pull request Jan 27, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant