Skip to content

Close the output descriptor after an early extraction error - #119

Open
jeromeyyy wants to merge 2 commits into
antelle:masterfrom
jeromeyyy:fix/extract-output-descriptor
Open

jeromeyyy wants to merge 2 commits into
antelle:masterfrom
jeromeyyy:fix/extract-output-descriptor

Conversation

@jeromeyyy

Copy link
Copy Markdown

Fixes #116.

When the entry stream errors before the output file's fs.open callback completes, extraction closes the closure-scoped archive descriptor (fd) instead of the output descriptor (fdFile). The output remains open and a later zip.close() attempts to close the archive descriptor a second time.

Change that error branch to close fdFile.

The regression uses the existing corrupt-entry fixture and StreamZip.setFs to hold the output-open callback until the real entry stream emits its error. It checks that the original error reaches the extraction callback, only the output descriptor is closed at that point, and the archive can still be closed normally. It does not depend on a timer or filesystem speed, and restores the filesystem hook after the test.

Validation:

  • Regression on original code: 2 of 4 assertions fail (output not closed, archive close returns EBADF).
  • Regression with fix: 4 assertions pass, including five repeated runs.
  • Full suite with CI-matching Node v25.9.0: 389 assertions pass (baseline: 385).
  • npm run lint, npm run check-types, and git diff --check pass.
  • On local Node v22.23.4, the unchanged baseline suite fails its existing callback exception test. That unrelated behavior is not changed here; full-suite results above are for Node 25, matching this repository's CI configuration.

Only the one-line descriptor fix and regression test are included. No dependency, type declaration, or formatting-only changes. Both published files at head 03c88a8 were compared byte-for-byte with the tested files through a fresh clone. CI results are not yet known.

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.

extract() error path closes the archive descriptor instead of the output file

1 participant