Skip to content

Fix file handle leak in zip extraction when the source stream errors#325585

Open
aturzone wants to merge 1 commit into
microsoft:mainfrom
aturzone:fix/zip-extract-filehandle-leak
Open

Fix file handle leak in zip extraction when the source stream errors#325585
aturzone wants to merge 1 commit into
microsoft:mainfrom
aturzone:fix/zip-extract-filehandle-leak

Conversation

@aturzone

Copy link
Copy Markdown
Contributor

extractEntry() pipes the zip entry's read stream into a createWriteStream target. stream.pipe(istream) does not destroy the destination when the source errors, so on a corrupt/truncated entry the source 'error' handler rejected the promise but left istream (the target file handle) open, leaking the fd and a partially-written file. The cancellation path already destroys istream; the source-error path did not.

Destroy istream in the source 'error' handler, mirroring the existing cancellation cleanup.

Assisted-by: Claude Code (Opus 4.8)

extractEntry() pipes the zip entry's read stream into a createWriteStream
target. stream.pipe(istream) does not destroy the destination when the
source errors, so on a corrupt/truncated entry the source 'error' handler
rejected the promise but left istream (the target file handle) open,
leaking the fd and a partially-written file. The cancellation path already
destroys istream; the source-error path did not.

Destroy istream in the source 'error' handler, mirroring the existing
cancellation cleanup.

Assisted-by: Claude Code (Opus 4.8)
Copilot AI review requested due to automatic review settings July 13, 2026 09:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Closes the destination stream when ZIP source extraction fails, preventing file descriptor leaks.

Changes:

  • Destroys the target write stream on source errors.
  • Rejects extraction with the original source error.

Comment thread src/vs/base/node/zip.ts
Comment on lines +98 to +100
// `stream.pipe()` does not destroy the destination when the
// source errors, so close the target file handle explicitly to
// avoid leaking it (mirrors the cancellation path above).
Comment thread src/vs/base/node/zip.ts
// `stream.pipe()` does not destroy the destination when the
// source errors, so close the target file handle explicitly to
// avoid leaking it (mirrors the cancellation path above).
istream.destroy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants