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

using writeZip() twice throws "Invalid LOC header (bad signature)" error #507

Merged
merged 2 commits into from
Jun 16, 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
15 changes: 15 additions & 0 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ describe("adm-zip", () => {
expect(zip1Entries).to.deep.equal(["windows/system32/drivers/etc/hosts.txt", "system32/drivers/etc/hosts.txt", "drivers/etc/hosts.txt", "hosts.txt"]);
});

// Issue 64
it("zip.writeZip - multiple times", () => {
const zip = new Zip("./test/assets/ultra.zip");
const fileName = pth.resolve(destination, "writezip");

for (let i = 0; i < 5; i++) zip.writeZip(`${fileName}.${i}.zip`);

const expected_list = ["./test/xxx/writezip.0.zip", "./test/xxx/writezip.1.zip", "./test/xxx/writezip.2.zip", "./test/xxx/writezip.3.zip", "./test/xxx/writezip.4.zip"].map(
pth.normalize
);

const files = walk(destination);
expect(files.sort()).to.deep.equal(expected_list);
});

/*
it("repro: symlink", () => {
const zip = new Zip("./test/assets/symlink.zip");
Expand Down
14 changes: 14 additions & 0 deletions zipFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ module.exports = function (/*Buffer|null*/ inBuffer, /** object */ options) {
}
mh.copy(outBuffer, dindex);

// Since we update entry and main header offsets,
// they are no longer valid and we have to reset content
// (Issue 64)

inBuffer = outBuffer;
loadedEntries = false;

return outBuffer;
},

Expand Down Expand Up @@ -371,6 +378,13 @@ module.exports = function (/*Buffer|null*/ inBuffer, /** object */ options) {

mh.copy(outBuffer, dindex); // write main header

// Since we update entry and main header offsets, they are no
// longer valid and we have to reset content using our new buffer
// (Issue 64)

inBuffer = outBuffer;
loadedEntries = false;

onSuccess(outBuffer);
}
};
Expand Down