Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion dist/jszip.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!

JSZip v3.11.1 - A JavaScript class for generating and reading zip files
JSZip v3.12.0 - A JavaScript class for generating and reading zip files
<http://stuartk.com/jszip>

(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
Expand Down Expand Up @@ -1906,6 +1906,17 @@ DataReader.prototype = {
(dostime >> 11) & 0x1f, // hour
(dostime >> 5) & 0x3f, // minute
(dostime & 0x1f) << 1)); // second
},
/**
* @returns {boolean} true if the reader is all zeros or has 0 length.
*/
isAllZeros: function() {
for (var i = 0; i < this.length; i++) {
if (this.byteAt(i) !== 0) {
return false;
}
}
return true;
}
};
module.exports = DataReader;
Expand Down Expand Up @@ -3870,6 +3881,10 @@ ZipEntries.prototype = {
this.readCentralDir();
this.readLocalFiles();
} catch (centralDirectoryError) {
if (this.reader.isAllZeros()) {
throw new Error("Corrupted zip: all zeros, unrecoverable");
}

if (this.loadOptions.recoverCorrupted) {
if (this.loadOptions.onCorruptCentralDirectory) {
this.loadOptions.onCorruptCentralDirectory(centralDirectoryError);
Expand Down
4 changes: 2 additions & 2 deletions dist/jszip.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions lib/reader/DataReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ DataReader.prototype = {
(dostime >> 11) & 0x1f, // hour
(dostime >> 5) & 0x3f, // minute
(dostime & 0x1f) << 1)); // second
},
/**
* @returns {boolean} true if the reader is all zeros or has 0 length.
*/
isAllZeros: function() {
for (var i = 0; i < this.length; i++) {
if (this.byteAt(i) !== 0) {
return false;
}
}
return true;
}
};
module.exports = DataReader;
4 changes: 4 additions & 0 deletions lib/zipEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ ZipEntries.prototype = {
this.readCentralDir();
this.readLocalFiles();
} catch (centralDirectoryError) {
if (this.reader.isAllZeros()) {
throw new Error("Corrupted zip: all zeros, unrecoverable");
}

if (this.loadOptions.recoverCorrupted) {
if (this.loadOptions.onCorruptCentralDirectory) {
this.loadOptions.onCorruptCentralDirectory(centralDirectoryError);
Expand Down
26 changes: 26 additions & 0 deletions test/asserts/corruption.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,30 @@ QUnit.module("corruption", function () {
})
.catch(JSZipTestUtils.assertNoError);
});

JSZipTestUtils.testZipFile("special error message for all zeros", "ref/zeros.bin", function(assert, file) {
var done = assert.async();
JSZip.loadAsync(file)
.then(function () {
assert.ok(false, "somehow successfully extracted zip of all zeros");
done();
})
.catch(function (err) {
assert.ok(err.message.match("all zeros"), "all zeros : the error message is useful");
done();
});
});

JSZipTestUtils.testZipFile("special error message for empty", "ref/empty.bin", function(assert, file) {
var done = assert.async();
JSZip.loadAsync(file)
.then(function () {
assert.ok(false, "somehow successfully extracted empty file");
done();
})
.catch(function (err) {
assert.ok(err.message.match("all zeros"), "empty : the error message is useful");
done();
});
});
});
Empty file added test/ref/empty.bin
Empty file.
Binary file added test/ref/zeros.bin
Binary file not shown.