Skip to content

Commit ed8a758

Browse files
authored
Merge pull request #544 from mljsgto222/invalid_extra_field_data
Fixed 'End of data reached' error when file extra field is invalid
2 parents bead269 + 7a99db8 commit ed8a758

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/zipEntry.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ ZipEntry.prototype = {
200200
this.extraFields = {};
201201
}
202202

203-
while (reader.index < end) {
203+
while (reader.index + 4 < end) {
204204
extraFieldId = reader.readInt(2);
205205
extraFieldLength = reader.readInt(2);
206206
extraFieldValue = reader.readData(extraFieldLength);
@@ -211,6 +211,8 @@ ZipEntry.prototype = {
211211
value: extraFieldValue
212212
};
213213
}
214+
215+
reader.setIndex(end);
214216
},
215217
/**
216218
* Apply an UTF8 transformation if needed.

test/asserts/load.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,18 @@ QUnit.module("load", function () {
570570
});
571571
});
572572

573+
JSZipTestUtils.testZipFile("zip file with extra field is Non-standard", "ref/extra_filed_non_standard.zip", function(assert, file) {
574+
var done = assert.async();
575+
JSZip.loadAsync(file)
576+
.then(function success() {
577+
assert.ok(true, "no exception were thrown");
578+
done();
579+
}, function failure(e) {
580+
assert.ok(false, "An exception were thrown: " + e.message);
581+
done();
582+
});
583+
});
584+
573585
QUnit.test("not a zip file", function(assert) {
574586
var done = assert.async();
575587
JSZip.loadAsync("this is not a zip file")

test/ref/extra_filed_non_standard.zip

22.5 MB
Binary file not shown.

0 commit comments

Comments
 (0)