Can't unzip .zip files created by OS X 10.12's native zipper
See original GitHub issueError
On Mac OS X 10.12.6 the native zip utility (right-click “compress folder”) creates a zip file that gives this error:
extra field length exceeds extra field buffer size
Not that I don’t believe it’s possible for Apple to make a mistake, but my guess is that the underlying zip utility is probably the same Unix / Darwin zip that has been in use for a very long time and that it’s statistically more likely to be a problem with this library.
For reference, here is the failing zip file (just a couple of test files for a website):
Example Zip File
I’ve attached fails-to-parse.zip for the test case.
The contents are as follows:
.
├── css
│ ├── custom.css
│ ├── plugins
│ │ └── bootstrap.css.min
│ └── styles.css
├── index-three.html
├── index-two.html
├── index.html
└── js
├── app.js
├── config.js
└── custom.js
I have also zipped files that do unzip just fine. My guess is that there’s some sort of off-by-one byte alignment issue.
Test Case
And a test case (based on the example):
mkdir -p /tmp/yauzl-test
pushd /tmp/yauzl-test
npm install yauzl@latest
touch test.js
wget -c https://github.com/thejoshwolfe/yauzl/files/1420073/fails-to-parse.zip
# => copy code below into test.js <= #
node test.js
test.js
:
'use strict';
var yauzl = require('yauzl');
yauzl.open('./fails-to-parse.zip', function (err, zipfile) {
if (err) throw err;
zipfile.readEntry();
zipfile.on('entry', function (entry) {
if (/\/$/.test(entry.fileName)) {
zipfile.readEntry();
return;
}
zipfile.openReadStream(entry, function(err, readStream) {
if (err) throw err;
readStream.on("end", function() {
zipfile.readEntry();
});
readStream.on("data", function (data) {
console.log("data of length", data.length);
});
});
});
zipfile.on('error', function (err) {
throw err;
});
zipfile.on('end', function () {
console.log("all entries read and processed");
});
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Installation Guide for Cisco Network Registrar 7.2 - PDF
Trivial File Transfer Protocol (TFTP). You can control these servers by using the Cisco Network Registrar web-based user interface (web UI).
Read more >yauzl - yet another unzip library for node - JsRepos
Sanitizing file names doesnt seem to solve it. opened by PanMan 10. Can't unzip .zip files created by OS X 10.12's native zipper...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much. I can confirm that several files that threw errors before now parse as expected…
I’m not sure how I didn’t add the
lazyEntries: true
before, but I’m just grateful for your help.Ah. Sorry about that. I was so focused on the zip file that I completely neglected to look at your sample code. My bad.
I am able to reproduce the issue now. The video helped!
The problem is that you’re using both
lazyEntries:false
andreadEntry()
. You probably forgot to put{lazyEntries:true}
in youryauzl.open()
call.This is such a easy mistake to make that I’m adding a check for it to throw an exception rather than this “undefined behavior”. This change should make this pitfall much more friendly to navigate. Here’s an example of what you get with this change:
And just for reference, the
{lazyEntries:true}
way is the recommended way, and the only reason it’s not the default is to maintain compatibility with earlier versions of yauzl.