diff --git a/lib/zipEntry.js b/lib/zipEntry.js index 39afdbd3..f204524e 100644 --- a/lib/zipEntry.js +++ b/lib/zipEntry.js @@ -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); @@ -211,6 +211,8 @@ ZipEntry.prototype = { value: extraFieldValue }; } + + reader.setIndex(end); }, /** * Apply an UTF8 transformation if needed. diff --git a/test/asserts/load.js b/test/asserts/load.js index 5b229661..c89978d5 100644 --- a/test/asserts/load.js +++ b/test/asserts/load.js @@ -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") diff --git a/test/ref/extra_filed_non_standard.zip b/test/ref/extra_filed_non_standard.zip new file mode 100644 index 00000000..56a4c8ec Binary files /dev/null and b/test/ref/extra_filed_non_standard.zip differ