Skip to content

Commit

Permalink
Merge pull request #544 from mljsgto222/invalid_extra_field_data
Browse files Browse the repository at this point in the history
Fixed 'End of data reached' error when file extra field is invalid
  • Loading branch information
Stuk committed Jun 13, 2020
2 parents bead269 + 7a99db8 commit ed8a758
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/zipEntry.js
Expand Up @@ -200,7 +200,7 @@ ZipEntry.prototype = {
this.extraFields = {};
}

while (reader.index < end) {
while (reader.index + 4 < end) {
extraFieldId = reader.readInt(2);
extraFieldLength = reader.readInt(2);
extraFieldValue = reader.readData(extraFieldLength);
Expand All @@ -211,6 +211,8 @@ ZipEntry.prototype = {
value: extraFieldValue
};
}

reader.setIndex(end);
},
/**
* Apply an UTF8 transformation if needed.
Expand Down
12 changes: 12 additions & 0 deletions test/asserts/load.js
Expand Up @@ -570,6 +570,18 @@ QUnit.module("load", function () {
});
});

JSZipTestUtils.testZipFile("zip file with extra field is Non-standard", "ref/extra_filed_non_standard.zip", function(assert, file) {
var done = assert.async();
JSZip.loadAsync(file)
.then(function success() {
assert.ok(true, "no exception were thrown");
done();
}, function failure(e) {
assert.ok(false, "An exception were thrown: " + e.message);
done();
});
});

QUnit.test("not a zip file", function(assert) {
var done = assert.async();
JSZip.loadAsync("this is not a zip file")
Expand Down
Binary file added test/ref/extra_filed_non_standard.zip
Binary file not shown.

0 comments on commit ed8a758

Please sign in to comment.