Skip to content

Commit

Permalink
Merge pull request #543 from issacgerges/master
Browse files Browse the repository at this point in the history
Add check for local desc flag in crc check
  • Loading branch information
5saviahv authored Sep 22, 2024
2 parents 9a29f09 + 62146bd commit 1cd32f7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions headers/entryHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file added test/crc/good_crc_trailing_data_descriptor.zip
Binary file not shown.
18 changes: 18 additions & 0 deletions test/crc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion zipEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1cd32f7

Please sign in to comment.