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

JSZip producing archives with bad crc32 / zipfile offset in some instances #936

Open
mikethea1 opened this issue Dec 17, 2024 · 0 comments

Comments

@mikethea1
Copy link

I'm using JSZip to generate zip archives in the browser containing image files which are generated via a canvas.

It works great nearly all the time, but very rarely the zip archives generated contain a sequence of partially corrupted files. This produces unzip -t output like this:

...
testing: some_file.jpeg              bad CRC b643aaa0  (should be 0b443b13)
file #24:  bad zipfile offset (local header sig):  77528
file #25:  bad zipfile offset (local header sig):  186714
file #26:  bad zipfile offset (local header sig):  280620
file #27:  bad zipfile offset (local header sig):  367435
file #28:  bad zipfile offset (local header sig):  462321
file #29:  bad zipfile offset (local header sig):  566764
file #30:  bad zipfile offset (local header sig):  643411
file #31:  bad zipfile offset (local header sig):  709539
file #32:  bad zipfile offset (local header sig):  789450
file #33:  bad zipfile offset (local header sig):  862629
file #34:  bad zipfile offset (local header sig):  936287
testing: another_file.jpeg             OK
...

In this case I'm able to extract the bad CRC 32 file with 7zip (which complains about the CRC but still extracts) and the file looks fine. However, the subsequent files with bad zipfile offset can't be extracted by 7zip.

I realize that debugging my specific file won't be possible here, but I'm wondering what could cause JSZip to produce a corrupted archive in the first place?

My zip generation code looks like this:

const jszip = await import('jszip');
        const zipArchive = new jszip.default();

        // generate deterministic zips
        const entryOptions = {
            date: new Date(1704067200000) // 2024-01-01
        };

        // Does not seem to get corrupted
        zipArchive.file("metadata.json", JSON.stringify({
            // various metadata fields
        }), entryOptions);

        // textFiles is an array of File objects created from strings.
        // These do not seem to get corrupted
        for (const textFile of textFiles) {
            zipArchive.file(textFile.name, textFile, entryOptions);
        }

        // images is an array of JS File objects created from Blobs
        for (const image of images) {
            zipArchive.file(image.name, image, entryOptions);
        }
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

1 participant