diff --git a/headers/entryHeader.js b/headers/entryHeader.js index 6f54e7a..c2c35be 100644 --- a/headers/entryHeader.js +++ b/headers/entryHeader.js @@ -221,6 +221,8 @@ module.exports = function () { _localHeader.version = data.readUInt16LE(Constants.LOCVER); // general purpose bit flag _localHeader.flags = data.readUInt16LE(Constants.LOCFLG); + // desc flag + _localHeader.flags_desc = (_localHeader.flags & Constants.FLG_DESC) > 0; // compression method _localHeader.method = data.readUInt16LE(Constants.LOCHOW); // modification time (2 bytes time, 2 bytes date) diff --git a/test/crc/good_crc_trailing_data_descriptor.zip b/test/crc/good_crc_trailing_data_descriptor.zip new file mode 100644 index 0000000..e208087 Binary files /dev/null and b/test/crc/good_crc_trailing_data_descriptor.zip differ diff --git a/test/crc/index.js b/test/crc/index.js index cf2a01d..4da686f 100644 --- a/test/crc/index.js +++ b/test/crc/index.js @@ -26,6 +26,24 @@ describe("crc", () => { }); }); + it("Good CRC - trailing data descriptor ", (done) => { + const goodZip = new Zip(path.join(__dirname, "good_crc_trailing_data_descriptor.zip")); + const entries = goodZip.getEntries(); + assert(entries.length === 1, "Good CRC: Test archive contains exactly 1 file"); + + const testFile = entries.filter(function (entry) { + return entry.entryName === "lorem_ipsum.txt"; + }); + assert(testFile.length === 1, "Good CRC: lorem_ipsum.txt file exists as archive entry"); + + const testFileEntryName = testFile[0].entryName; + goodZip.readAsTextAsync(testFileEntryName, function (data, err) { + assert(!err, "Good CRC: error object not present"); + assert(data && data.length, "Good CRC: buffer not empty"); + done(); + }); + }); + it("Bad CRC - async method returns err string", (done) => { const badZip = new Zip(path.join(__dirname, "bad_crc.zip")); const entries = badZip.getEntries(); diff --git a/zipEntry.js b/zipEntry.js index e7804b6..0e506ce 100644 --- a/zipEntry.js +++ b/zipEntry.js @@ -30,7 +30,7 @@ module.exports = function (/** object */ options, /*Buffer*/ input) { function crc32OK(data) { // if bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the local header is written - if (!_centralHeader.flags_desc) { + if (!_centralHeader.flags_desc && !_centralHeader.localHeader.flags_desc) { if (Utils.crc32(data) !== _centralHeader.localHeader.crc) { return false; }