thejoshwolfe / yauzl

yet another unzip library for node
MIT License
736 stars 80 forks source link

Invalid signature causes process to close unexpectedly #136

Closed Portur closed 9 months ago

Portur commented 4 years ago

Hi,

When unzipping a file (~40kb) I get a signature error (Uncaught Error: invalid central directory file header signature: 0xbfef2b1c) and the process immediately stops and ends nodejs.

I noticed the error emitted in emitErrorAndAutoClose

Below is how I use it. You'll notice the try/catch is ignored (?)

        let yauzl = require("yauzl");
        try {

            yauzl.open(file_path, {lazyEntries: true}, function (err, zipfile) {
                if (err)
                    reject('Could not unzip > ' + err);
                else {
                    zipfile.readEntry();
                    zipfile.on("entry", function (entry) {
                        if (entry.fileName === 'doc.kml') {
                            // stuff
                        }
                        else {
                            zipfile.readEntry();
                        }
                    });
                }
            });
        }
        catch (e) {
            reject(e)
        }

Here is the stack image

Not sure f it makes a difference but this specific file has made it rounds through various email clients. Also this is a kmz, which is a zipped kml which is sugar for zipped xml.

Here it is https://storage.googleapis.com/coverage-hosting-public/Clear%20Access%20FTTH%20August%202020.kmz

Portur commented 4 years ago

More digging, it seems the file is actually opened and is uncaught.

The problem is there are no events created for error


                    zipfile.on("close", function() {
                        console.log("closed yauzl read");
                    });
                    zipfile.on("error", function(e) {
                        console.log("error yauzl read");
                    })

With those created I catch the error successfully. Could I recommend that in a case where the user forgets to add those listeners, could you perhaps throw rather than shutdown

thejoshwolfe commented 9 months ago

there is a section of the docs that explains how to avoid crashing the process.