Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for local desc flag in crc check #543

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions headers/entryHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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