node-unzip icon indicating copy to clipboard operation
node-unzip copied to clipboard

Hangs with potentially corrupted/invalid/empty zip files

Open domharrington opened this issue 11 years ago • 6 comments

Create an empty file:

$ touch a.zip

Try and unzip using this module:

var fs = require('fs')
  , unzip = require('unzip')
  , os = require('os')
  , zipFile = fs.createReadStream(__dirname + '/a.zip')
  , unzipper = unzip.Extract({ path: os.tmpdir() + '/test', verbose: true })

zipFile.on('error', function (err) {
  console.error('Zip file error:', err)
})

unzipper.on('error', function (err) {
  console.error('Unzipper error:', err)
})

unzipper.on('close', function () {
  console.log('Unzipper closed')
})

zipFile.pipe(unzipper)

Hangs forever. Outputting the following verbose log only:

/t/node-unzip-test ❯❯❯ node test.js                                                                                                                                                                       ⏎
Archive:  /private/tmp/node-unzip-test/a.zip

I dont know too much about zip files in general. Is there any way to detect corruption and emit an error somewhere along the line when things arent as they should be?

domharrington avatar Jun 23 '14 14:06 domharrington

This is not an issue in yauzl.

andrewrk avatar Oct 16 '14 00:10 andrewrk

I ended up using https://github.com/bower/decompress-zip to detect for corrupted zip files, then this module to stream unzip the contents.

domharrington avatar Oct 16 '14 10:10 domharrington

That's a bit of a brittle solution. Seems like you would want the same library that is doing the unzipping to be the one to detect errors and not crash. Anyway if you've got it working then you've got it working. But I do think yauzl would be a more elegant solution :-)

andrewrk avatar Oct 16 '14 17:10 andrewrk

Yeah I agree. If i work on the code again i'll definitely check it out. The failure test cases fill me with confidence https://github.com/thejoshwolfe/yauzl/tree/master/test/failure

domharrington avatar Oct 17 '14 07:10 domharrington

I encountered the same problem when the destination is unwriteable. e.g. try running domharrington's code with a real zip file, then chmod -rwx some of the destination files, and try running it again. It will hang forever. An uncaught error is thrown, but neither the error nor close events fire.

mpcomplete avatar May 01 '15 04:05 mpcomplete

+1 had the same problem, switched over to use yauzl which seems like the better choice long term (this one has had no activity since last year)

jameshowe avatar Nov 02 '15 12:11 jameshowe