Skip to content

zip does not support >65,535 files #229

@kajkal

Description

@kajkal

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions