Skip to content

Commit 62146bd

Browse files
author
Issac Gerges
committed
Add check for local desc flag in crc check
1 parent 1c7860f commit 62146bd

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

headers/entryHeader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ module.exports = function () {
220220
_localHeader.version = data.readUInt16LE(Constants.LOCVER);
221221
// general purpose bit flag
222222
_localHeader.flags = data.readUInt16LE(Constants.LOCFLG);
223+
// desc flag
224+
_localHeader.flags_desc = (_localHeader.flags & Constants.FLG_DESC) > 0;
223225
// compression method
224226
_localHeader.method = data.readUInt16LE(Constants.LOCHOW);
225227
// modification time (2 bytes time, 2 bytes date)
1.49 KB
Binary file not shown.

test/crc/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ describe("crc", () => {
2626
});
2727
});
2828

29+
it("Good CRC - trailing data descriptor ", (done) => {
30+
const goodZip = new Zip(path.join(__dirname, "good_crc_trailing_data_descriptor.zip"));
31+
const entries = goodZip.getEntries();
32+
assert(entries.length === 1, "Good CRC: Test archive contains exactly 1 file");
33+
34+
const testFile = entries.filter(function (entry) {
35+
return entry.entryName === "lorem_ipsum.txt";
36+
});
37+
assert(testFile.length === 1, "Good CRC: lorem_ipsum.txt file exists as archive entry");
38+
39+
const testFileEntryName = testFile[0].entryName;
40+
goodZip.readAsTextAsync(testFileEntryName, function (data, err) {
41+
assert(!err, "Good CRC: error object not present");
42+
assert(data && data.length, "Good CRC: buffer not empty");
43+
done();
44+
});
45+
});
46+
2947
it("Bad CRC - async method returns err string", (done) => {
3048
const badZip = new Zip(path.join(__dirname, "bad_crc.zip"));
3149
const entries = badZip.getEntries();

zipEntry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function (/** object */ options, /*Buffer*/ input) {
3030

3131
function crc32OK(data) {
3232
// 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
33-
if (!_centralHeader.flags_desc) {
33+
if (!_centralHeader.flags_desc && !_centralHeader.localHeader.flags_desc) {
3434
if (Utils.crc32(data) !== _centralHeader.localHeader.crc) {
3535
return false;
3636
}

0 commit comments

Comments
 (0)