diff --git a/index.js b/index.js index 8c193e4..4f3275d 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,12 @@ module.exports = function (zipPath, opts, cb) { var cancelled = false + zipfile.on('error', function(err) { + if (err) { + cancelled = true; + return cb(err); + } + }) zipfile.readEntry() zipfile.on('close', function () { diff --git a/test/broken.zip b/test/broken.zip new file mode 100644 index 0000000..5aa6788 Binary files /dev/null and b/test/broken.zip differ diff --git a/test/test.js b/test/test.js index b124527..42a0ed4 100644 --- a/test/test.js +++ b/test/test.js @@ -11,6 +11,7 @@ var githubZip = path.join(__dirname, 'github.zip') var subdirZip = path.join(__dirname, 'file-in-subdir-without-subdir-entry.zip') var symlinkDestZip = path.join(__dirname, 'symlink-dest.zip') var symlinkZip = path.join(__dirname, 'symlink.zip') +var brokenZip = path.join(__dirname, 'broken.zip') var relativeTarget = './cats' @@ -193,3 +194,13 @@ test('files in subdirs where the subdir does not have its own entry is extracted }) }) }) + +test('extract broken zip', function (t) { + t.plan(2) + + mkdtemp(t, 'broken-zip', function (dirPath) { + extract(brokenZip, {dir: dirPath}, function (err) { + t.ok(err, 'Error: invalid central directory file header signature: 0x2014b00') + }); + }); +})