Skip to content

Commit 1cd32f7

Browse files
authored
Merge pull request #543 from issacgerges/master
Add check for local desc flag in crc check
2 parents 9a29f09 + 62146bd commit 1cd32f7

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

headers/entryHeader.js

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

test/crc/index.js

+18
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

+1-1
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)