Skip to content
Open
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
6 changes: 4 additions & 2 deletions node_stream_zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ StreamZip.debugLog = (...args) => {
util.inherits(StreamZip, events.EventEmitter);

const propZip = Symbol('zip');
const propZipInstance = Symbol('zipInstance');

StreamZip.async = class StreamZipAsync extends events.EventEmitter {
constructor(config) {
Expand All @@ -677,6 +678,7 @@ StreamZip.async = class StreamZipAsync extends events.EventEmitter {
zip.on('entry', (entry) => this.emit('entry', entry));
zip.on('extract', (entry, outPath) => this.emit('extract', entry, outPath));

this[propZipInstance] = zip;
this[propZip] = new Promise((resolve, reject) => {
zip.on('ready', () => {
zip.removeListener('error', reject);
Expand Down Expand Up @@ -746,9 +748,9 @@ StreamZip.async = class StreamZipAsync extends events.EventEmitter {
}

async close() {
const zip = await this[propZip];
await this[propZip].catch(() => {});
return new Promise((resolve, reject) => {
zip.close((err) => {
this[propZipInstance].close((err) => {
if (err) {
reject(err);
} else {
Expand Down
4 changes: 4 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release notes
-------------
##### v1.16.1 (2026-09-15)
`-` fix #96, #94: file handle leak in the async API when the archive could not be read
`*` async `close()` now resolves instead of rejecting when the archive could not be read, matching the callback API

##### v1.16.0 (2026-07-22)
`+` fixed reading compressed entry size to prevent exploitation reported by @DumDumSu
`*` updated dependencies
Expand Down
26 changes: 26 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,32 @@ module.exports['async.entryData'] = async (test) => {
test.done();
};

module.exports['async.close'] = async (test) => {
test.expect(2);
const fd = fs.openSync('test/ok/normal.zip', 'r');
const zip = new StreamZip.async({ fd });
test.equal(await zip.entriesCount, 10);
await zip.close();
test.throws(() => fs.fstatSync(fd), /EBADF/);
test.done();
};

module.exports['async.close on a bad archive'] = async (test) => {
test.expect(3);
const fd = fs.openSync('test/err/rar.rar', 'r');
const zip = new StreamZip.async({ fd });
try {
await zip.entries();
test.ok(false, 'Should throw an error');
} catch (e) {
test.equal(e.message, 'Bad archive');
}
test.ok(fs.fstatSync(fd));
await zip.close();
test.throws(() => fs.fstatSync(fd), /EBADF/);
test.done();
};

module.exports.setUp = function (done) {
testPathTmp = basePathTmp + testNum++ + '/';
if (!fs.existsSync(basePathTmp)) {
Expand Down